Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
这是有效的jquery条件语句吗?_Jquery_Conditional - Fatal编程技术网

这是有效的jquery条件语句吗?

这是有效的jquery条件语句吗?,jquery,conditional,Jquery,Conditional,但似乎还不清楚。。。任何建议 我正在定制一个表单插件 if (tag == 'td' && $(this).hasClass('status')) { // I am clearing everything inside the td with class status $(this).html('') } 为什么不干脆做: $.fn.clearForm = function() { return this.each(funct

但似乎还不清楚。。。任何建议

我正在定制一个表单插件

 if (tag == 'td' && $(this).hasClass('status')) {
        // I am clearing everything inside the td with class status
        $(this).html('')
    }
为什么不干脆做:

$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea' )
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
        else if (tag == 'td' && $(this).hasClass('status')) {
            // if you want to remove everything, use this
            $(this).html('');
        }
    });
};
为什么不干脆做:

$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea' )
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
        else if (tag == 'td' && $(this).hasClass('status')) {
            // if you want to remove everything, use this
            $(this).html('');
        }
    });
};
查看代码(在编辑中),并假设您通过执行类似于
$(“#myForm”).clearForm()的操作调用函数(其中
myForm
是表单元素),那么它永远不会处理
td
元素。代码采用一种形式&然后递归到该形式的上以清除它们。鉴于
td
不是
输入
,它们将不包括在清算中

如果这就是您使用它的方式,您可以按如下方式对其进行自定义,以使其清除您的
td
s(在表单中):

查看代码(在编辑中),并假设您通过执行类似于
$(“#myForm”).clearForm()的操作调用函数(其中
myForm
是表单元素),那么它永远不会处理
td
元素。代码采用一种形式&然后递归到该形式的上以清除它们。鉴于
td
不是
输入
,它们将不包括在清算中

如果这就是您使用它的方式,您可以按如下方式对其进行自定义,以使其清除您的
td
s(在表单中):


@潘迪亚:你怎么称呼这个插件?@Pandiya-Oops,我显然没有读我贴的东西。该行位于返回语句之后。:)现在修好了。@Alconja ya我看起来也没修好that@Pandiya:你怎么称呼这个插件?@pandiya-Oops,我显然没有读我发布的内容。该行位于返回语句之后。:)现在修好了。@Alconja ya我也不这么认为
$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form') {
            $('td.status', this).empty();
            return $(':input', this).clearForm();
        }
        if (type == 'text' || type == 'password' || tag == 'textarea' )
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
};