[英]jquery inside javascript function not working
I am trying to use jquery code inside javascript function but it is not working,the inside javascript function there is jquery code which should open pop up . 我正在尝试在javascript函数内使用jquery代码,但无法正常工作,在javascript函数内有应打开弹出的jquery代码。 on clicking iframe
在点击iframe时
Working 工作
<script>
window.onload = function() {
document.querySelector("iframe").contentWindow.document.body.onclick = function(){
alert("Hello World!");
};
};
</script>
not working code 不起作用的代码
window.onload = function() {
document.querySelector("iframe").contentWindow.document.body.<?php echo $event;?> = function(){
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("slow",0.9);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
};
};
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
//alert('ok');
$(this).hide();
$('.window').hide();
});
It looks like a typo in your click handler declaration. 您的点击处理程序声明中看起来像是一个错字。 There is a piece of php code that looks like it shouldn't be there.
有一段看起来不应该存在的php代码。
document.querySelector("iframe").contentWindow.document.body.<?php echo $event;?>
Replace the code above with the actual name of the event you want to bind to. 将上面的代码替换为您要绑定的事件的实际名称。 In this case the
onclick
event. 在这种情况下,
onclick
事件。
document.querySelector("iframe").contentWindow.document.body.onclick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.