【问题标题】:how get target children id如何获取目标儿童ID
【发布时间】:2014-04-14 09:13:54
【问题描述】:

简短的英文...

我的html

<button><span id="popMain"> pop </span></button>

$(document).bind({
click : function(evt){
var targetID = evt.target.id;
var nodeName = evt.target.nodeName;
}
  • 来自 chrome 的点击事件 (nodeName : SPAN)
  • 来自资源管理器的点击事件(节点名:BUTTON)

当使用资源管理器时,我想得到 span 的 ID。

我试试

$(this).find('span').attr('id');
$(this).find('span').id;
$("#"+evt.target.id).children('span').attr('id');
$("#"+evt.target.id).find('span:first-child').attr('id');
$("#"+evt.target.id).find('span:last-child').attr('id');

但结果是“未定义”。 T^T 请帮助我...

【问题讨论】:

  • $("#"+evt.target.id).childeren('span').attr('id');更改为$("#"+evt.target.id).children('span').attr('id');

标签: jquery html find children


【解决方案1】:

拼写错误:

$(this).find('span').attr('id');
$(this).find('span').id;
$("#"+evt.target.id).childeren('span').attr('id'); // children not childeren.
$("#"+evt.target.id).find('span:first-child').attr('id');
$("#"+evt.target.id).find('span:last-child').attr('id');

【讨论】:

  • 谢谢.. T^T 我解决了.. [ $("#"+evt.target.id).children('span').attr('id'); ]
【解决方案2】:

这在资源管理器上对我有用:

$("span:first").attr('id');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    相关资源
    最近更新 更多