2010-05-20 38 views
0
if (tag == 'td' && $(this).hasClass('status')) { 
     // I am clearing everything inside the td with class status 
     $(this).html('') 
    } 

但它似乎并不清楚...任何建议...这是一个有效的jQuery条件语句?

我定制表单插件,

$.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(''); 
     } 
    }); 
}; 

回答

1

查看代码(在您的编辑中),并假设您通过执行诸如$('#myForm').clearForm()(其中myForm是表单元素)来调用该函数,那么我ts永远不会处理td元素。代码采用&的形式,然后递归到该表单的:input elements以清除它们。鉴于td不是input,它们将不包含在清算中。

如果这是您如何使用它,可以按如下方式得到它清除td S(表格中),以及自定义:在我的编辑

$.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; 
    }); 
}; 
+0

@Alconja任何其他的可能性... – 2010-05-20 04:27:46

+0

@Pandiya:你怎么打电话给插件? – Alconja 2010-05-20 04:31:48

+0

@alconja'$(“#addform”)。clearForm();' – 2010-05-20 04:33:14

2

为什么不只是做:

$('td.status').empty(); 
+1

看看... – 2010-05-20 04:23:42