jquery
  • asp.net
  • textbox
  • reset
  • 2012-07-12 50 views 1 likes 
    1

    當它設置爲只讀= true或Enabled = false時,我需要清除/重置文本框值。我在我的代碼中使用了重置功能,但這不起作用。 我作爲使用jquery清除表單中已啓用的文本框

    function resetForm($form) { 
        $form.find('input:text, input:password, input:file, select').val(''); 
        $("input[type='hidden']", this).each(function() { 
         this.value = ''; 
        });  
        $form.find('input:checkbox') 
         .removeAttr('checked').removeAttr('selected'); 
    
    } 
    
    <asp:TextBox ID="txteventid" runat="server" ReadOnly="true"/> 
    

    任何建議代碼..

    回答

    2

    我不知道你的復位功能做的,因爲我看不到if conditionread only檢查,但你可以嘗試這樣的:從給定的<您代碼:>:)

    即使用API​​; .prophttp://api.jquery.com/prop/和檢查什麼是屬性或屬性的狀態:

    其餘希望這有助於你的目的:)

    ,如果你渴望:.prop() vs .attr()

    這可能來得心應手:Select elements by attribute

    function resetForm($form) { 
        $form.find('input:text, input:password, input:file, select').val(''); 
        $("input[type='hidden']", this).each(function() { 
         if($(this).prop('readonly')){ // you could check with string i.e. $(this).prop('readonly') === "true" 
         this.value = ''; 
         } 
        });  
        $form.find('input:checkbox') 
         .removeAttr('checked').removeAttr('selected'); 
    
    } 
    
    <asp:TextBox ID="txteventid" runat="server" ReadOnly="true"/> 
    
    +0

    不,它不工作,你能告訴this.prop('只讀')指定文本框? – kk1076 2012-07-12 10:50:58

    +0

    嘿@ kk1076你可以彈出一個演示; (**)或**爲這個'alert($('#txteventid')。prop('ReadOnly'))發出一個提示信息;'知道你會得到什麼作爲回報,我們會整理出來,不用擔心 – 2012-07-12 10:53:11

    +0

    好。如上所述,警報顯示爲未定義。我嘗試瞭如果$('MainContent_uscEventParameters_txteventid')。prop('ReadOnly')){document.getElementById(「'MainContent_uscEventParameters_txtevent」)。value =「」; }但它沒有清除價值。 – kk1076 2012-07-12 11:16:38

    相關問題