2012-04-17 141 views
1

我有一個單選按鈕,我希望在單選按鈕中的特定值未選中(選中)時禁用文本字段。我正在使用dojo的單選按鈕。你能幫我解決這個問題嗎?單選按鈕事件處理

<dt><label for="Records_Size">Test Run Size</label></dt> 
    <dd> 
     <input id="Records_All" type="radio" dojoType="dijit.form.RadioButton" name="SourceQuery" checked 
     value="All"></input> 
     <label for="Records_All">All input records</label> 
    </dd> 
    <dt>&nbsp;</dt> 
    <dd> 
     <span><input id="Records_Query" type="radio" dojoType="dijit.form.RadioButton" name="SourceQuery" 
     value="Query" ></input> 
     <label for="Records_Query">Limit input records to:</label></span><span>&nbsp;<input type="text" 
     dojoType="dijit.form.TextBox" id="Row_Count" style="width: 25px;" value="10"/></span> 
    </dd> 

The radio buttons on my UI

基本上,我需要觸發每當這個按鈕失去焦點的事件和事件時,它獲得回來,但處理是兩個不同的事件。

回答

2

如果你想爲這個純粹的客戶端活動,那麼......

<script> 
function ManageTextBox(el){ 
    t=document.getElementById('Row_Count'); 
    if (el.value=='Query') {t.disabled=false} 
     else {t.disabled=true} 
    } 
</script> 

<dt><label for="Records_Size">Test Run Size</label></dt> 
<dd> 
    <input id="Records_All" type="radio" dojoType="dijit.form.RadioButton" name="SourceQuery" checked 
    value="All" onchange="ManageTextBox(this)"></input> 
    <label for="Records_All">All input records</label> 
</dd> 
<dt>&nbsp;</dt> 
<dd> 
    <span><input id="Records_Query" type="radio" dojoType="dijit.form.RadioButton" name="SourceQuery" 
    value="Query" onchange="ManageTextBox(this)"></input> 
    <label for="Records_Query">Limit input records to:</label></span><span>&nbsp;<input type="text" 
    dojoType="dijit.form.TextBox" id="Row_Count" style="width: 25px;" value="10"/ disabled></span> 
</dd> 

注意,每個單選按鈕得到一個onchange屬性,因爲「全部」單選按鈕,開始了檢查,文本盒子需要從disabled開始。更改單選按鈕的值將調用改變文本框狀態的函數,具體取決於按鈕的新值。

http://jsfiddle.net/LyStj/