我有:
<div id="d1">
<label>title</label>
<div class="col">
<select id="location.state.id">...</select>
</div>
</div>
基本上,我想禁用/启用 <select>
。我有类似的东西:
$("#d1").find("#location.state.id").prop("disabled", true);
这不起作用。我错过了什么?
最佳答案
问题是你的id
属性的值为 .
里面。
自 .
类名的 CSS 选择器,jQuery 将查找 ID 为 location
的项目和 CSS 类 state
和id
,而不是 ID 为 location.state.id
的元素.
您必须使用\\
之前.
在查询选择器中使用它们(在 CSS 中,只有 \
就可以了):
$('#d1').find('location\\.state\\.id').prop('disabled', true);
<小时/>
To use any of the meta-characters (such as
!"#$%&'()*+,./:;<=>?@[\]^``{|}~
) as a literal part of a name, it must be escaped with with two backslashes:\\
. For example, an element withid="foo.bar"
, can use the selector$("#foo\\.bar")
.
关于javascript - jQuery 向下查找多个级别的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32958374/