I have a set of dynamically generated anchor tags in a for loop as follows:(我在for循环中有一组动态生成的锚标记,如下所示:)
<div id = "solTitle"> <a href = "#" id = "' + tagId + '" onClick = "openSolution();"> ' + solTitle + '</a></div> <br>';
Once this code is executed the html output for one of the case would look like:(执行此代码后,其中一个案例的html输出将如下所示:)
<div id = "solTitle"> <a href = "#" id = "solution0" onClick = "openSolution();">Solution0 </a></div> <br>
<div id = "solTitle"> <a href = "#" id = "solution1" onClick = "openSolution();">Solution1 </a></div> <br>
Now I want different texts to be displayed on clicking the above links.(现在我希望在点击上面的链接时显示不同的文本。) openSolution() looks like this:(openSolution()看起来像这样:)
function openSolution() {
alert('here');
$('#solTitle a').click(function(evt) {
evt.preventDefault();
alert('here in');
var divId = 'summary' + $(this).attr('id');
document.getElementById(divId).className = '';
});
}
When I execute it and click on either of the links, the flow doesnot come inside the jquery click handler.(当我执行它并单击任一链接时,流不会进入jquery单击处理程序。) I checked it by the above alerts used.(我通过上面使用的警报检查了它。) It only displays the alert - 'here' and not the alert - 'here in'.(它只显示警报 - “此处”而非警报 - “此处”。) On clicking the link second time, everything works perfectly with correct value of divId.(在第二次单击链接时,一切都与divId的正确值完美匹配。)
ask by crazy_coder translate from so