0

I have some several labels on a webpage, that can be clicked, and all share the class 'btn'. In the console, if I use the selector $('.btn'); among others the following elements DO appear:

<label id=​"skillstable_Certification" class=​"row btn">​Certification​&lt;/label>​,
<label id=​"skillstable_Compliance" class=​"row btn">​Compliance​&lt;/label>​,
<label id=​"skillstable_Technology" class=​"row btn">​Technology​&lt;/label>​,
<label id=​"skillstable_version(s)​" class=​"column btn">​Version(s)​&lt;/label>,​
<label id=​"skillstable_startdate" class=​"column btn">​StartDate​&lt;/label>​,
<label id=​"skillstable_enddate" class=​"column btn">​EndDate​&lt;/label>​,
<label id=​"skillstable_elapsedtime" class=​"column btn">​ElapsedTime​&lt;/label>,​
<label id=​"skillstable_expertiserating" class=​"column btn">​ExpertiseRating​&lt;/label>,​

which matches the HTML:

</fieldset>
  <label id="fs_skillstable_heading" class="fs btn heading skillstable">Skills Table</label><br class="">
  <label id="skillstable_Certification" class="row btn">Certification</label>
  <label id="skillstable_Compliance" class="row btn">Compliance</label>
  <label id="skillstable_Technology" class="row btn">Technology</label><br class="">
  <label id="skillstable_version(s)" class="column btn">Version(s)</label><br class="">
  <label id="skillstable_startdate" class="column btn">StartDate</label><br class="">
  <label id="skillstable_enddate" class="column btn">EndDate</label><br class="">
  <label id="skillstable_elapsedtime" class="column btn">ElapsedTime</label><br class="">
  <label id="skillstable_expertiserating" class="column btn">ExpertiseRating</label><br class="">
</fieldset>

however, these elements only are not registering with the $('.btn').on('click', function() {...}) function, which has a console.log() section to show that it has been clicked. They all have the .btn class, so I am totally lost here. I am trying to make an array to use for persistence, and made a quick variable with .push() to show all the elements I have clicked on so i can use that string to make a persistent URL, but noticed that these sections only are not registering.

The generation for the elements are scoped within a self calling function (function TCC() {...})();, so I tried pulling them out of that function and calling them individually, but that did not work either. I also switched the functions from .click() to .on('click', function(){}) to no avail.

Here is the webpage.

4

4 回答 4

2

尝试这个; on()用法:

编辑:@David Thomas 提到this.id;会比$(this).attr('id');

$(document).on('click','.btn',function() {
    var whichPart = this.id;
    console.log(whichPart);
});

这是jsFiddle。

于 2012-07-31T14:07:24.903 回答
1

出现此问题是因为您在“列按钮生成器”循环之前绑定了单击事件。最简单的解决方法是使用“现场”活动

$('.btn').live('click',function(){...})

或者,为循环创建一个回调并绑定点击事件。

于 2012-07-31T14:20:15.557 回答
0

You can test the sample code on following link:

http://jsfiddle.net/shivkant/ueHNg/4/

于 2012-07-31T14:13:19.257 回答
0

您的页面适用于我的 chrome,我单击左侧部分的专业知识/技能/工具等,如果这是您想要的,它会显示我在右侧橙色部分中单击的链接。

如果控制台/开发人员工具已经打开,它可以在 IE 中运行,这可能是因为您在代码中使用了 console.log 语句

参考这个

IE8 中的 console.log 发生了什么?

于 2012-07-31T14:46:47.800 回答