van*_*van 2 jquery jquery-selectors radio-button
当用户选择Otherradiobutton组中的特定单选按钮()时,我正在尝试使用jQuery来显示div .
html如下
<div id="countries">
<input id="Washington_D.C" type="radio" name="location" value="Washington">Washington D.C</input>
<input id="Other" type="radio" name="location" value="">Other</input>
<div id="other locations" style="display: none">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使用JQuery代码:
$(document).ready(function(){
$("radio[@name='location']").change(function(){
if ($("radio[@name='location']:checked").val() == 'Other')
$("#county_drop_down").show();
});
});
Run Code Online (Sandbox Code Playgroud)
但是当我选择radiobutton时,它并没有显示div其他位置Other.
你需要给它一个值Other.
因此,不是这样
<input id="Other" TYPE="RADIO" NAME="location" VALUE="">Other</input>
Run Code Online (Sandbox Code Playgroud)
但是这样
<input id="Other" TYPE="RADIO" NAME="location" VALUE="Other">Other</input>
Run Code Online (Sandbox Code Playgroud)
乍一看,你的jQuery代码看起来很好.但是我更喜欢click上面的内容change,因为change如果没有预先选择的话,不会在第一次点击时被解雇.
| 归档时间: |
|
| 查看次数: |
14821 次 |
| 最近记录: |