我已经试过教程了,但还是不能工作,出什么问题了?
父页面脚本:
<!DOCTYPE html>
<html>
<head>
<title>Parent</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.slim.js"></script>
<script>
$(function() {
var money = 20000;
$("#iframe1").contents().find("#nominal").on("change keyup", function() {
var input = $(this);
// remove possible existing message
if( input.next().is("form") )
input.next().remove();
// show message
if( input.val() > money )
alert('Hello');
});
});
</script>
</head>
<body>
<iframe id="iframe1" src="iframe.html">
</iframe>
</body>
</html>Iframe脚本:
<!DOCTYPE html>
<html>
<head>
<title>Iframe</title>
</head>
<body>
<input type="text" id="nominal" value="" />
</body>
</html>请告诉我出了什么问题,谢谢预支。
发布于 2016-07-21 16:12:16
clickiframe,等click先加载等完成后再监听事件
首先,在click事件侦听器完成后加载iframe,如load。
试试这个:
<!DOCTYPE html>
<html>
<head>
<title>Parent</title>
<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
<script>
$(function() {
$("#iframe1").attr("src","iframe.html");
//iframe加载完毕以后执行的事件
$("#iframe1").load(function(){
console.log('loaded...');
Handle();
})
});
function Handle(){
var money = 20000;
$("#iframe1").contents().find("#nominal").on("change keyup", function() {
var input = $(this);
// remove possible existing message
if( input.next().is("form") )
input.next().remove();
// show message
if( input.val() > money )
alert('Hello');
});
}
</script>
</head>
<body>
<iframe id="iframe1">
</iframe>
</body>
</html>https://stackoverflow.com/questions/38497584
复制相似问题