簡體   English   中英

jQuery在隱藏時重置表單輸入的值

[英]jQuery resetting value of form input when hidden

我試圖從用戶中隱藏“其他”表單輸入的值屬性,如下所示:

// 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("");

我設法以這種方式更改了其他屬性,例如名稱,maxlength等。

有任何想法嗎?

另外,您可以在隱藏前或顯示后不久清除其值。 或嘗試以下方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM