1
我想在javascript函數內部使用jquery代碼,但它不工作,裏面的JavaScript函數有jQuery代碼,應該打開彈出窗口。上點擊IFRAMEjquery裏面的JavaScript函數不工作
工作
<script>
window.onload = function() {
document.querySelector("iframe").contentWindow.document.body.onclick = function(){
alert("Hello World!");
};
};
</script>
不工作密碼
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();
});
請檢查您有錯誤或不函數是否觸發或不 – guradio
檢查生成的HTML和分享 - 如果它是在一個瀏覽器用戶查看源代碼選項,查看生成的HTML –
有這裏還有一段PHP代碼:'<?php echo $ event;?'。請檢查(並分享)實際輸出的代碼(因爲它在瀏覽器中),並檢查Javascript控制檯(F12 - >控制檯)以查看是否有錯誤。 – GolezTrol