2010-04-21 68 views
1

我试图清除“其他”的形式输入的数值属性,当它从用户隐藏,像这样的时候:jQuery的重置价值隐藏

// hide 'Other' inputs to start 
$('.jOther').hide(); 

// event listener on all select drop downs with class of jTitle 
$("select.jTitle").change(function(){ 

    //set the select value 
    var $titleVal = $(this).val(); 

    if($titleVal != 'Other') { 
     $(this).parent().find('.jOther').hide(); 
     $(this).parent().find('input.jOther').attr("value", ""); 
    } else { 
     $(this).parent().find('.jOther').show(); 
    } 

    // Sets a cookie with named after the title field's ID attribute   
    var $titleId = $(this).attr('id'); 

    $.cookies.set('cpqb' + $titleId, $titleVal); 

}); 

这似乎并没有被工作,我曾尝试以下无济于事还有:

$(this).parent().find('input.jOther').val(""); 

我设法改变这种方式的其他属性,如名称,最大长度等

任何想法?

回答

1

作为一种替代方法,您可以在隐藏之前或在显示之后立即清除其值。或试试这个:

$('input.jOther:hidden').val('');