小编Mic*_*cah的帖子

jQuery .fn说"不是函数"

当我调用这个自定义函数时

$.fn.inputBoxHelper = function () {
    var args = arguments[0] || {};
    var matchingElem = $.grep(this, function (e) { return $(e).val() == $(e).attr('title'); });
    $(matchingElem).addClass(args.className);

    this.bind({
        focus: function(){
            if ($(this).val().trim() == $(this).attr('title')) { $(this).val(emptyString).removeClass('gray'); }
        },
        blur: function(){
            if ($(this).val().trim() == emptyString) { $(this).val($(this).attr('title')).addClass('gray'); }
        }
    });
    return this;
}
Run Code Online (Sandbox Code Playgroud)

像这样

$('input:text').inputBoxHelper({ className: 'gray' });
Run Code Online (Sandbox Code Playgroud)

当我打电话给它时,它给了我错误

$("input:text,input:checkbox").inputBoxHelper is not a function
file:///D:/repository/scripts/script_tests/test.js
Line 20
Run Code Online (Sandbox Code Playgroud)

即使我将功能更改为just

$.fn.inputBoxHelper = function () {return this;}
Run Code Online (Sandbox Code Playgroud)

它做了同样的事情.它似乎运行正常并且正常工作,因为所有功能都在输入框上工作,但是会出错.有人有主意吗?

javascript jquery

7
推荐指数
1
解决办法
9477
查看次数

标签 统计

javascript ×1

jquery ×1