我想检查名为weekday的输入,并且value = 1.我尝试下面的行.它检查所有平日.
$('input[name = weekday],[value =1]').attr("checked","checked");
解决方法
不要使用逗号在同一个元素上同时应用这两个条件.
$('input[name=weekday][value=1]').attr("checked","checked");
作为附注,您应该使用prop()而不是attr()用于jQuery doc建议并由@tyleha指向的属性.
As of jQuery 1.6,the .attr() method returns undefined for attributes
that have not been set. To retrieve and change DOM properties such as
the checked,selected,or disabled state of form elements,use the
.prop() method.
您可以使用.prop( propertyName,value )设置选中的属性,如下所示.
$('input[name=weekday][value=1]').prop("checked",true);