Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.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函数问题_Javascript_Jquery_Function - Fatal编程技术网

JavaScript函数问题

JavaScript函数问题,javascript,jquery,function,Javascript,Jquery,Function,我无法将此函数作为函数参数显示警报。我比较了一些例子,看不出导致它不起作用的问题。我已经在下面介绍了我的html和JavaScript,对于我遇到的问题,我们将非常感谢您的帮助。谢谢 HTML: 你只是打错了。将newmodelcontrols更改为newmodalcontrols JavaScript $(document).ready(function () { $.fn.newmodalcontrols = function (modelspec) { alert

我无法将此函数作为函数参数显示警报。我比较了一些例子,看不出导致它不起作用的问题。我已经在下面介绍了我的html和JavaScript,对于我遇到的问题,我们将非常感谢您的帮助。谢谢

HTML:


你只是打错了。将newmodelcontrols更改为newmodalcontrols

JavaScript

$(document).ready(function () {

    $.fn.newmodalcontrols = function (modelspec) {
        alert(modelspec);
    }

    $('#testlink').click(function () {
        $(this).parent().newmodalcontrols('number1');
    });

});

更新:添加了一个。

您有一个输入错误:
newmodalcontrols
newmodelcontrols
是不等价的(注意
a
/
e
):

顺便提一下,在Chromium中,这将在Web Inspector的JavaScript控制台中显示为:

Uncaught TypeError: Object [object Object] has no method 'newmodelcontrols'
这应该引起您对正在使用/定义的方法名称的注意。

您输入了一个错误

检查小提琴

$(文档).ready(函数(){


});//end ready

JavaScript控制台中报告的任何错误(
F12
在大多数浏览器中)?是的,它显示以下…未捕获的类型错误:对象[Object Object]没有方法“newmodelcontrols”testjs.js:10(匿名函数)testjs.js:10 jQuery.event.dispatch jQuery.js:3074 elemData.handle请检查testjs.js是否正确加载花了几个小时的时间,现在感觉很傻。谢谢:)谢谢你们的帮助,解决了问题,吸取了教训。A@Ant字体没问题,我很高兴能帮上忙!
$(document).ready(function () {

    $.fn.newmodalcontrols = function (modelspec) {
        alert(modelspec);
    }

    $('#testlink').click(function () {
        $(this).parent().newmodalcontrols('number1');
    });

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

    $.fn.newmodalcontrols = function (modelspec) {
        alert(modelspec);
    } // end newmodalcontrols
      //           ^- Should be an 'e'

    $('#testlink').click(function () {
        $(this).parent().newmodelcontrols('number1');
        //                     ^- Or this should be an 'a'
    }); // end testlink click function

}); // end ready
Uncaught TypeError: Object [object Object] has no method 'newmodelcontrols'
$.fn.newmodelcontrols = function (modelspec) {
    alert(modelspec);
}; // end newmodalcontrols


$('#testlink').click(function () {
    $(this).parent().newmodelcontrols('number1');
}); // end testlink click function