本文介绍了jQuery:选择具有给定名称和值的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查命名为平日且值为1的输入.我尝试了下面的行.它会检查所有工作日.
I want to check the input that is named weekday and has value = 1. I tried the line below. It checks all weekdays.
$('input[name = weekday], [value =1]').attr("checked", "checked");
推荐答案
请勿使用逗号将两个条件应用于同一元素.
Do not use comma to apply both conditions on same element.
$('input[name=weekday][value=1]').attr("checked", "checked");
请注意,对于,您应该使用 prop()代替attr()
属性,如 jQuery文档所述,并由@tyleha指出.
As a side note you should use prop() instead of attr()
for properties as suggested by jQuery doc and pointed by @tyleha.
您可以使用 .prop(propertyName,value)来设置检查属性,如下所示.
You can use .prop( propertyName, value ) to set the checked property as shown below.
$('input[name=weekday][value=1]').prop("checked", true);
这篇关于jQuery:选择具有给定名称和值的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!