【发布时间】:2017-02-20 18:40:59
【问题描述】:
我有这个代码,
$('#gogo').click(function(e){
var data='<a href="http://www.google.com" class="myButtons">Google</a><a href="http://www.microsoft.com" class="myButtons">Microsoft</a>";
$("#showResults").html(data);
});
$(".myButtons").click(function(e) {
e.preventDefault();
alert($(this).attr("href"));
$("#result").attr("src", $(this).attr("href"));
});
<button id="gogo">Click me</button>
<div id="showResults"></div>
<iframe id="result" name="result" src="" width="750px" height="450px" frameBorder="0"></iframe>
我想知道为什么它不起作用。也许是因为没有新添加的 html 标签的事件处理程序?
我不想使用 target="result"
谢谢。
【问题讨论】:
标签: jquery html class src attr