如何在jquery的单个单元格中标识特定的td元素和hyperlink元素

如何在jquery的单个单元格中标识特定的td元素和hyperlink元素,jquery,Jquery,你能用上面的问题修改我的代码吗 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">

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

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>
jQuery.noConflict()(函数(jQ){
“严格使用”;
//处理花名册中的每个表格单元格
jQ(“wb#u i”)。单击(函数(事件){
警报(“Hi”);
});
});
测验

您可以尝试类似的方法

/* 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"
});

首先,你的html是无效的。锚定标记必须有结束标记,
是正确的用法。请看

其次,如果您想获得点击事件的具体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)
});


这实际上取决于在这方面单击了什么,希望我在代码中的注释足够了。

这里测试<代码>警报(“如何在jquery的单个单元格中识别特定的td元素和超链接元素”)。。。完全按照要求;-)想为td和超链接使用类名,那么ituse“.td_class”的代码是什么来查找类为“td_class”的元素更改其中的值。查找:如何使用此代码生成上下文菜单我正在动态获取json数据,仅使用我想要的显示上下文菜单..基于超链接类名,我只想在Jquery中生成上下文菜单请提供示例代码问另一个问题。除此之外,我不会给你免费的代码。这不是这个网站的目的。它是关于帮助人们解决现有代码中存在的问题。