<input type="radio" name="Radio" id="radio1" value="1" checked="checked" />
<label for="radio1">11111</label>
<input type="text" name="1" id="1" /><input type="radio" name="Radio" id="radio2" value="2" />
<label for="radio2">22222</label>
<input type="text" name="2" id="2" />
目前的效果是点击 11111 和 22222 分别能使 radio1 和 radio2 选中,我想当我在 文本框1 中输入文字的时候 自动使 radio1 选中,在 文本框2 中输入文字的时候 自动使 radio2 选中。请问该如何写?
<script type="text/javascript">
<!--
function checkRadio(id){
document.getElementById('radio' + id).checked = true;
}
//-->
</script>
<input type="radio" name="Radio" id="radio1" value="1" checked="checked" />
<label for="radio1">11111</label>
<input type="text" name="1" id="1" onclick="checkRadio(this.id)"/>
<input type="radio" name="Radio" id="radio2" value="2" />
<label for="radio2">22222</label>
<input type="text" name="2" id="2" onclick="checkRadio(this.id)"/>
为了代码便于阅读,一般radio我加个前缀,然后是数字。比如 Aradio1、 Aradio2 ...
同时文本框叫做 Atext1、 Atext2 ... 请问这样该如何写?
<script type="text/javascript">
<!--
function checkRadio(id){
document.getElementById('Aradio' + id.replace(/\D/g,'')).checked = true;
}
//-->
</script>
<input type="radio" name="Radio" id="Aradio1" value="1" checked="checked" />
<label for="radio1">11111</label>
<input type="text" name="1" id="Atext1" onclick="checkRadio(this.id)"/>
<input type="radio" name="Radio" id="Aradio2" value="2" />
<label for="radio2">22222</label>
<input type="text" name="2" id="Atext2" onclick="checkRadio(this.id)"/>