gpt4 book ai didi

javascript - 问题调试脚本 $(this).find 不是函数

转载 作者:行者123 更新时间:2023-11-30 10:51:04 25 4
gpt4 key购买 nike

我在调试这个脚本时遇到问题,最初的问题是“$().ready 不是一个函数”所以我包装了这部分脚本:

$(document).ready(function()
{ $('#jsddm > li').bind('mouseover', jsddm_open);
$('#jsddm > li').bind('mouseout', jsddm_timer);});

document.onclick = jsddm_close;

像这样向上

 ( function($) { 
$(document).ready( function() {

$('#menu-main-nav > li').bind('mouseover', jsddm_open);
$('#menu-main-nav > li').bind('mouseout', jsddm_timer);
});

document.onclick = jsddm_close;

} ) ( jQuery );

但我现在得到一个 $(this).find is not a function on the line "jsddm_close();"- 感谢任何帮助,我相信这很简单。完整脚本如下:

<script type="text/javascript">
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{ jsddm_canceltimer();
jsddm_close();
ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{ if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{ if(closetimer)
{ window.clearTimeout(closetimer);
closetimer = null;}}

( function($) {

$(document).ready( function() {

$('#menu-main-nav > li').bind('mouseover', jsddm_open);
$('#menu-main-nav > li').bind('mouseout', jsddm_timer);

});

document.onclick = jsddm_close;

} ) ( jQuery );

</script>

最佳答案

你应该在一个匿名函数中包装 e'erbody...

<script type="text/javascript">

(function($) {

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
jsddm_canceltimer();
jsddm_close();
ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close() {
if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer() {
closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
if (closetimer) {
window.clearTimeout(closetimer);
closetimer = null;
}
}


$(document).ready( function() {
$('#menu-main-nav > li').bind('mouseover', jsddm_open);
$('#menu-main-nav > li').bind('mouseout', jsddm_timer);
});

document.onclick = jsddm_close;

})(jQuery)

</script>

关于javascript - 问题调试脚本 $(this).find 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5317275/

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