gpt4 book ai didi

JavaScript 在页面回发时失败

转载 作者:行者123 更新时间:2023-11-28 01:15:18 26 4
gpt4 key购买 nike

我已经有了这个脚本来给我拥有的按钮带来效果,在页面回发后它失败了,我还将代码放入 pageLoad 方法中,但它仍然不起作用。知道如何在页面加载后运行此脚本吗?

$(document).ready(function () {

/*preloader for image loading bar*/

jQuery(function ($) {
function preLoad() {
//alert("script running");
$("#divQuestionMatrix").addClass("hidden");
}

function loaded() {
$("#divQuestionMatrix").removeClass("hidden");
$('div#preLoader').css({ display: 'none' }).remove();
}

preLoad();
window.onload = loaded;
});

/* End of preloader*/



$("#btnPrevious").click(function (e) {
$("#navigation").val("previous");
}
);
$("#btnNext").click(function (e) {
$("#navigation").val("next");
}
);

/* $(".qmatrix").click(function () {
//get id of button
alert($(this).attr('id'));
$("#navigation").val($(this).attr('id'));
}
);*/

$(".qmatrix").hover(function (e) {
//get id of button
//alert($(this).attr('id'));
//get src of image before hover
var origimage = $(this).attr('src');
// alert(origimage);
//$(this).attr({ src: 'images/questionMatrix/100' + $(this).attr('id') + '.png' });
$(this).stop().animate({ "opacity": "0.1" }, "fast")
},
function () {
// $(this).attr({ src: '' + origimage.toString() + '' });
$(this).stop().animate({ "opacity": "1" }, "fast");
}
);

最佳答案

页面加载完成后,就会触发 document.ready 事件。

在就绪事件的处理程序中,您可以使用就绪事件快捷方式(将函数直接传递给全局 jQuery 函数(与全局 $ 函数相同)为就绪事件添加另一个处理函数。

在第二个就绪处理程序中,您尝试将加载的函数分配给 window.onload,此时该函数已经被触发。

关于JavaScript 在页面回发时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23906345/

26 4 0