javascript - 选择器 'nth-last-child(n)' 在 chrome 中不起作用

标签 javascript jquery css

alert($('#Content_tab form .form-group:nth-last-child(2)').html());

nth-last-child(n) 上的这个和更多选择在 chrome 中不起作用!!

他们如何在所有其他浏览器中正常工作,例如在 IE8、Mozilla 中。

请查看我的 Sitesource code

you can find the code near line no. 502

最佳答案

使用这个

$('#Content_tab form .form-group').eq(-2).html()

作为一名 javascript 开发人员,我一点也不喜欢那个选择器。使用那种选择器再次成为我的规则。这将是非常不高效的。您可以在构建标记时为该元素提供一些类,或者这样更好。

$("#Content_tab").find(".form-group").eq(-2).html()

关于javascript - 选择器 'nth-last-child(n)' 在 chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21003819/

相关文章:

javascript - 如何使用 javascript 使用来自 php 函数的数组元素填充 <div> 元素?

javascript - 如何在回调中访问正确的“this”?

javascript - Xamarin Android Webview Javascript

jquery - 调整 bootstrap div 大小以适合内容

jquery 在输入焦点上将类添加到父级

css - 如何隐藏 div 的溢出?

javascript - Lodash js 检查值是否与 null 不同

javascript - 运行 2 document.ready 会使它们发生冲突吗?

javascript - 如何防止事件在子元素中被激活?

html - 为什么 margin :auto doesn't work?