-4

你能用上面的问题修改我的代码吗::

jQuery.noConflict()(function(jQ) {
    "use strict";

    //Process each table cell in the roster
    jQ("#wb_i").click(function(event) {
        alert('Hi');
    });
});

<td id="dd" class="dd1">
    <div id="x" class="y"> <a href="aaa" id="m" class="aa" />Test</> </div>
</td>
4

2 回答 2

0

你可以试试这样的

/* code emmitted */
//Process each table cell in the roster
jQ("#wb_i").click(function(event) {
    var tds = jQ(this).find("td"); //will give you all td's
    var links = jQ(this).find("a"); //will give you all hyperlinks in the whole table
    var tdsFromClass = jQ(this).find(".td_class"); //will give you td's with the class "td_class"
});
于 2012-08-01T06:30:35.280 回答
0

首先,您的 html 无效。锚标签必须有一个结束标签,<a />不起作用,</>甚至不是一个标签。 <a href="etc">test</a>是正确的用法。请参阅此文档以获取正确的语法

其次,如果你想获取点击事件的具体td/a,下面应该做你需要的:

jQ("#wb_i").click(function(event) {
    console.log(jQ(event.target)); //the anchor element(if the anchor was clicked)
    console.log(jQ(event.target).closest("td")); //the td element
    console.log(jQ(event.target).find("a")); //the anchor element(if the div was clicked)
});

演示

这真的取决于在这方面点击了什么,希望我在代码中的评论就足够了。

于 2012-08-01T06:53:09.257 回答