我有一个脚本,显示一些并隐藏一些html,但我不知道如何添加所需的标记,当它显示,我已经尝试添加属性的部分,我想要它,但它需要它即使不显示...有人可以帮助我。提前致谢!所有的如何添加必填属性?
<div class="start"><select name="start" class="form-control">
<option value="0" class="select">Select City</option>
<?php foreach($rows as $row): ?>
<option <? echo 'value="'.$row['id'].'"';
echo ($row['id'] == $job['start'])?' selected>':'>';
echo $row['name']; ?></option>
<?php endforeach; ?>
</select></div><br />
<br />
<script>
$('select[name=start]').change(function() {
if ($(this).val() == '89') {
$('#otherStart').show();
} else {
$('#otherStart').hide();
}
});
</script>
<br />
<div id="otherStart">
<input type="text" name="otherStart" placeholder="Other City" <? echo ($job['otherStart'])?' value="'.$job['otherStart'].'"':'';
?> class="form-control" >
</div>
的'required'属性?将它添加到什么元素和什么时候? '$('#otherStart')。show()。attr(“required”,“required”);'。你应该用'jquery'来标记你的问题,因为你正在使用它。 – Arg0n