[英]jquery selector
I have a table,m using some function for that table.I want those functions to work only on that table not in any other part. 我有一个表,该表使用了某些功能。我希望这些功能只能在该表上工作,而不能在其他任何部分上工作。
Is this correct? 这个对吗? $(div#xxx) can i use function after this
$(div#xxx)之后我可以使用函数吗
$(div#xxx function({
});
You can restrict the scope of a selector that applies to by giving it as the context to the jQuery function. 您可以通过将选择器作为上下文提供给jQuery函数来限制选择器的范围。 Note that the context must be a document, element, or jQuery (not a raw selector).
请注意,上下文必须是文档,元素或jQuery(而不是原始选择器)。
Example: attach a click handler to anchors inside table foo , but not to any other anchors on the page. 示例:将单击处理程序附加到表foo内的锚点上,而不附加到页面上的任何其他锚点上。
$('a',$('table#foo')).click( function() {
...
});
Alternatively, you can use the ancestor/descendant or parent/child selectors, choose by name, etc. 或者,您可以使用祖先/后代或父/子选择器,按名称选择,等等。
$('table#foo a').click( function() {
// ancestor descendant
});
$('table#foo > tbody > tr > td > a').click( function() {
// parent > child (must be direct child)
});
$('a#inside-foo').click( function() {
// a link by id, presumably inside table foo
});
$('a.inside-foo').click( function() {
// a link by class, presumably applied only to links inside table foo
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.