HTML:
<form id="form_filter" action="{{ Request::fullUrl() }}" method="post">
<input type="checkbox" name="shape[]" value="Aviator">
<input type="checkbox" name="shape[]" value="Round">
<input type="checkbox" name="shape[]" value="Oval">
</form>
我需要通过[名称]和[值]获取元素:
$('#form_filter input[name=shape][value=Round]').prop('checked', true);
请帮忙!
最佳答案
您在名称值中漏掉了[]
,它应该是name="shape[]"
$('#form_filter input[name="shape[]"][value=Round]').prop('checked', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="form_filter" action="{{ Request::fullUrl() }}" method="post">
<input type="checkbox" name="shape[]" value="Aviator">
<input type="checkbox" name="shape[]" value="Round">
<input type="checkbox" name="shape[]" value="Oval">
</form>
关于JavaScript、Jquery : get element by two attr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53760606/