gpt4 book ai didi

javascript - On click 函数转换为 on load 函数

转载 作者:行者123 更新时间:2023-12-03 12:30:34 24 4
gpt4 key购买 nike

我有代码

$(function() {
// run the currently selected effect
function runEffect() {
// get effect type from
var selectedEffect = $( "#effectTypes" ).val();

// most effect types need no options passed by default
var options = {};
// some effects have required parameters
if ( selectedEffect === "scale" ) {
options = { percent: 100 };
} else if ( selectedEffect === "size" ) {
options = { to: { width: 280, height: 185 } };
}

// run the effect
$( "#effect" ).show( selectedEffect, options, 500, callback );
};

//callback function to bring a hidden box back
function callback() {
setTimeout(function() {
$( "#effect:visible" ).removeAttr( "style" ).fadeOut();
}, 1000 );
};

// set effect from select menu value
$( "#button" ).click(function() {
runEffect();
});

像dis一样,我想将dis on click功能更改为on load功能,我是初学者,所以请帮助我

最佳答案

如果我理解正确的话,您想在页面加载时运行 runEffect 函数吗?

您可以通过从 jQuery 就绪事件中调用该函数来完成此操作。

// This is shorthand for $(document).ready(function() { ... })
$(function() {
// Declare the runEffect function here

runEffect();
});

关于javascript - On click 函数转换为 on load 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23951073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com