2012-06-07 99 views
0

例如,當文本框旁邊的編輯按鈕被單擊時,我的頁面上有一個文本框,該文本框中已經有一些值,並且它的只讀選項爲「true」 ,文本框中的編輯選項被啓用。當我點擊一個按鈕時,如何實現啓用文本框。 如何在單擊按鈕時啓用/禁用文本框

function func() { 
    $("input:button[name='button1']").click(function() { 
     $("#text11").val($(this).val()).attr("disabled", "disabled"); 
     if($(this).val() != "") { 
      $("#text11").attr("disabled", "").focus(); 
     } 
    }); 
} 
<input type="text" name="text11" readonly="readonly" value="Editing is disabled"> 
<input type="button" value="edit" name="button1"> 

這是當我點擊該按鈕,在文本框中的只讀選項應disabled.How做呢?

+2

請發佈您嘗試過的代碼。 – j08691

+0

編輯 <腳本類型= 「文本/ JavaScript的」> 函數func() { $( 「輸入:按鈕[名= '按鈕1']」)。單擊(函數(){ $ ($(this).val()!=「」){ $((#)(。#text11) 「#text11」)。attr(「disabled」,「」).focus(); } }); } –

+1

您可以編輯您的問題以添加代碼 – PeeHaa

回答

0

您需要使用HTML DOM對象...

http://www.w3schools.com/jsref/default.asp

+5

這個答案可能是更好的imo的uuhhhmmm。 1)你可以在這裏舉一些例子,而不僅僅是一些鏈接。 2)w3schools不是那裏最好的資源 – PeeHaa

+0

它有點幫助!謝謝 –

+0

@ 20911141 w3schools永遠不會是一個很好的選擇,所以請不要暗示這 –

2

基本上你只是想禁用添加到您的元素用它來阻止用戶的屬性。

$('#disablebutton').click(function(){ 
    $('#textfieldToClose').attr('disable'); 
}); 

<input type="text" name="text11" readonly="readonly" id="textfieldToClose"> 
<input type="button" value="edit" name="button1" id="disablebutton"> 

我相信這應該工作,沒有測試過它的頭腦。

相關問題