我加载了一个 iframe,我想将一个点击事件附加到每个锚点。模式是从链接触发的。
更新:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>Simple Modal Test</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.simplemodal-1.3.5.js"></script>
</head>
<body>
<a id="showModal" href="#">Trigger Simple Modal</a>
<script type="text/javascript">
$(function(){
$('#showModal').click(function(e){
$.modal('<iframe src="mylinks.html'" height="400" width="600" style="border:0">', {
onShow:function(dialog){
$('a', dialog.data).click(function(){
// do something
alert('You clicked me!');
});
}
});
return false;
});
});
</script>
</body>
</html>
这就是我在 mylinks.html 中的内容:
<a href="http://www.google.com" target="_new">Google</a>
<a href="http://www.yahoo.com" target="_new">Yahoo!</a>
我正在使用 jQuery 1.4.2 和 Simplemodal 版本 1.3.5。我还在 1.3.2 中测试了这段代码,即使在 FF 或 IE7 中也有同样的问题。有人可以告诉我我做错了什么吗?
谢谢!Ĵ