Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery setTimeout-无法读取属性';防止违约';未定义的_Javascript_Jquery - Fatal编程技术网

Javascript jQuery setTimeout-无法读取属性';防止违约';未定义的

Javascript jQuery setTimeout-无法读取属性';防止违约';未定义的,javascript,jquery,Javascript,Jquery,我有这样的脚本: $(document).on('focus.inputmask.data-api', '[data-mask]', function (e) { var $this = $(this) if ($this.data('inputmask')) return e.preventDefault() $this.inputmask($this.data()) }); Uncaught TypeError: Cannot read property '

我有这样的脚本:

$(document).on('focus.inputmask.data-api', '[data-mask]', function (e) {
    var $this = $(this)
    if ($this.data('inputmask')) return
    e.preventDefault()
    $this.inputmask($this.data())
});
Uncaught TypeError: Cannot read property 'preventDefault' of undefined 
我想为这个函数设置超时,这就是我尝试的

$(document).on('focus.inputmask.data-api', '[data-mask]', setTimeout(function (e) {
    var $this = $(this)
    if ($this.data('inputmask')) return
    e.preventDefault()
    $this.inputmask($this.data())
}, 10))
但我在控制台上看到的错误如下所示:

$(document).on('focus.inputmask.data-api', '[data-mask]', function (e) {
    var $this = $(this)
    if ($this.data('inputmask')) return
    e.preventDefault()
    $this.inputmask($this.data())
});
Uncaught TypeError: Cannot read property 'preventDefault' of undefined 

很明显,
e
将根据您的代码
未定义
,因为您在
.on()
函数的回调函数参数处传递了一个
超时
对象

试试看


感谢您的回答,我确信您提供的解决方案是正确的,但我仍然得到相同的错误。我不知道为什么,但我认为问题在于其他脚本,实际上这个脚本是jquery插件的一部分,我不想对它做什么修改。我不能把所有的脚本都放在我的问题上,因为脚本行太多了。