[英]Javascript popup window not working
我管理一個我未建的站點。 該站點具有一些鏈接,您可以在其中單擊鏈接,然后將打開一個模式窗口,其中包含來自其他html文件的內容。 它曾經可以工作,現在卻不起作用。
我已經比較了從現在到接管該站點之間的所有相關文件,但是看不到會影響到此的任何更改。
彈出窗口因此被調用:
<?php bioLinkText('Daniel Jones', 'Read more about Dr. Jones'); ?></p>
它應該打開的頁面是/bios/daniel-jones.html
從functions.php文件中:
function bioLinkText($name,$text) {
$name = strtolower(str_replace(" ","-",$name));
echo '<a href="/bios/'.$name.'.html" class="popUp">'.$text.'</a>';}
這部分功能正常。 但是它曾經用來創建模式窗口,現在,它像常規鏈接一樣打開鏈接。
從global.js文件中:
// AJAX Popups
function popUp(page,randId) {
$('body').append(
'<div id="'+randId+'" class="pWin" style="display:none;position:fixed">'+
'<span class="pHead">'+
'<a href="'+page+'" target="_blank">Open in new window</a>'+
'<span class="pClose">X</span>'+
'</span>'+
'<div class="pBod"></div>'+
'</div>'
);
var top = (h/2) - 150;
var left = (w/2) - 300;
$('#'+randId+'.pWin').addClass('large').css({top:top+'px',left:left+'px'});
$('#'+randId+' .pBod').html('<img src="/images/loading.gif" alt="loading"/>').load(page+' #content', function() {
$('.pWin').show(300);
$('.pBod #content').find('img').filter('#portrait').attr('src', function(index, src) {
return '/bios/' + src;
});
});
}
$('.popUp').click(function() {
var randId = randomString();
var num = $('.pWin').length;
if (num < 5) {
var page = $(this).attr('href');
popUp(page,randId);
$('#'+randId+'.pWin').draggable({handle:'.pHead'}).resizable({alsoResize:'#'+randId+' .pBod', minWidth: 320, minHeight: 280, maxWidth: 800, maxHeight: 600});
}
return false;
});
function pClose(btn) {
var pWin = btn.closest('.pWin');
pWin.hide(200, function() { pWin.remove(); });
}
$('.pClose').live('click',function() {
var btn = $(this);
pClose(btn);
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$('.pWin').hide(200, function() { $('.pWin').remove(); });
}
});
從style.css文件中:
.popUp, .pHead a { padding-right: 16px; background: url(/images/external.gif) 100% 50% no-repeat; }
.popUp.noBg { background:none; padding-right:0; }
我已經嘗試解決了10多個小時。 任何幫助將不勝感激。 一件事是...我不明白如何調用javascript函數popUp。 那是缺少的成分嗎?
嘗試這個:
//Make sure the DOM is ready (If you call this function before '.popUp' exists, it wont be matched, and the '.click' handler wont be added.
$(document).ready(function() {
$('.popUp').click(function(e) {
//Prevent the default action (Clicking the button)
e.preventDefault();
//..Your code here
});
});
好吧,我知道了。 我更改了功能,在a href中添加了onclick =“ popup()”屬性,現在可以使用了:
function bioLinkText($name,$text) {
$name = strtolower(str_replace(" ","-",$name));
echo '<a href="/bios/'.$name.'.html" onclick="popup()" class="popUp">'.$text.'</a>';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.