2012-04-17 136 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/