javascript - jQuery 向下查找多个级别的子元素

标签 javascript jquery html

我有:

<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 类 stateid ,而不是 ID 为 location.state.id 的元素.

您必须使用\\之前.在查询选择器中使用它们(在 CSS 中,只有 \ 就可以了):

$('#d1').find('location\\.state\\.id').prop('disabled', true);
<小时/>

引用jQuery API

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 with id="foo.bar", can use the selector $("#foo\\.bar").

关于javascript - jQuery 向下查找多个级别的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32958374/

相关文章:

javascript - 访问对象字面量函数内的Jquery对象变量

javascript - 尝试在下拉列表中搜索具有标题名称的元素

javascript - csv将列交换为行javascript

jquery - 如何在类里面更改 Font Awesome ?

javascript - Angularjs 隔离了没有自己模板的指令范围

javascript - 如何使用 javascript 从 jQuery load() 操作 html

jquery - 如何将 $.getJSON 超时设置为无限期

javascript - jquery计算总金额但不显示

用于 Web 开发和模板的基于 Python CGI 的框架?

html - Kendo UI - 演示服务的源代码