您好我想知道如何在下拉框中添加required
属性?我搜索过很多种方法,但都没有用;这是我的代码:
<script>
$(document).ready(function(){
$('.orderingmenu .burgers').change(function(){
var selectVal= $(this).val();
if(selectVal != 'none'){
$(this).next().attr('required', true);
}
});
});
</script>
我真的没有关于如何做到这一点的想法,我测试了选择器并且它们工作正常,但它似乎没有在select字段中添加所需的属性= /任何帮助吗?< / p>
我试过的是:
$(this).next().prop('required', true);
$(this).next().attr('required', 'true');
$(this).next().attr('required', '');
$(this).next().prop('required');
没有工作= /
编辑 HTML:
<div class="orderingmenu" style="margin-bottom: 0.5%;">
<select name="burgerlist" class="burgers" style="width: 35%; float: left; font-size: 12px;">
<option selected="selected" value="none">NONE</option>
<option value="A">A</option>
</select>
<select name="option" id="option" class="setornot" style="width: 30%; font-size: 12px;">
<option selected="selected" value="none">NONE</option>
<option value="ALA CARTE">ALA CARTE</option>
<option value="SET">SET</option>
</select>
<input type="text" placeholder="ANY REMARKS?" name="remarks" style="width: 30%; float: right; font-size: 12px;">
</div>
我用php脚本循环,但基本上我想做的是,如果除了'none'之外还有其他选择,则需要其他选择。
编辑2
我发现问题在于我没有值!