Javascript jQuery将点击偶数更改为加载事件
我有下面的代码,我把它们放在一起,我需要将它从onclick事件更改为onload,这样当页面加载时它会自动加载模式窗口。然而,就我的一生而言,我不知道该怎么做,我尝试了许多排列,但似乎都不起作用Javascript jQuery将点击偶数更改为加载事件,javascript,jquery,html,Javascript,Jquery,Html,我有下面的代码,我把它们放在一起,我需要将它从onclick事件更改为onload,这样当页面加载时它会自动加载模式窗口。然而,就我的一生而言,我不知道该怎么做,我尝试了许多排列,但似乎都不起作用 $(document).ready(function() { $('a.poplight[href^=#]').click(function() { var popID = $(this).attr('rel'); var popURL = $(this)
$(document).ready(function() {
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel');
var popURL = $(this).attr('href');
var query = popURL.split('?');
var dim = query[1].split('&');
var popWidth = dim[0].split('=')[1];
$('#' + popID)
.fadeIn()
.css({ 'width': Number( popWidth ) })
.prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
return false;
});
$('a.close, #fade').live('click', function() {
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
});
return false;
});
});
$(文档).ready(函数(){
$('a.poplight[href^=#]')。单击(函数(){
var popID=$(this.attr('rel');
var popURL=$(this.attr('href');
var query=popURL.split(“?”);
var dim=query[1]。拆分('&');
var popWidth=dim[0]。拆分('=')[1];
$('#'+popID)
.fadeIn()
.css({'width':数字(popWidth)})
.prepend(“”);
var popMargTop=($('#'+popID).height()+80)/2;
var popMargLeft=($('#'+popID).width()+80)/2;
$('#'+popID).css({
“页边距顶部”:-popMargTop,
“左边距”:-popMargLeft
});
$('body')。追加('');
$('#fade').css({'filter':'alpha(不透明度=80)}).fadeIn();
返回false;
});
$('a.close,#fade').live('click',function(){
$('#淡入,.popup#u块')。淡出(函数(){
$(“#淡入,a.close”).remove();
});
返回false;
});
});
此时将加载它:
<a href="#?w=200" rel="popup_name" class="poplight">Popup</a>
非常感谢您的帮助,谢谢您尝试:
$('a.poplight[href^=#]').trigger("click");
或:
这些应该在DOM中准备就绪。如果您查找,您可以将弹出窗口的逻辑移动到它自己的函数中(在示例中称为popOpen()
),并在加载时调用它,如下所示:
$('a.poplight[href=#?w=200]').popOpen();
如果我理解正确,您可以尝试以下方法:
$(document).ready(function() {
$this = $('a.poplight[href^=#]');
var popID = $this.attr('rel');
....
你正在使用哪个弹出式插件?如果你查看它的文档,很可能会有一个
触发器
函数或类似的函数,它允许你通过代码以编程方式显示一个模式窗口,而不需要用户交互。没有插件,它都在上面的代码中:-)我刚刚用谷歌搜索了插件名称并找到了它。在文档中有一个关于在加载时设置弹出窗口的指南:谢谢你的朋友,我没有从那里得到它,所以我甚至没有想过用谷歌搜索它!救生员
$(document).ready(function() {
$this = $('a.poplight[href^=#]');
var popID = $this.attr('rel');
....