这是有效的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;
});
};