【发布时间】:2015-05-14 01:25:36
【问题描述】:
我有一个带有 3 个单选按钮和 3 个文本框的表单,单击单选按钮会显示一个输入字段,而其他两个隐藏(使用 jQuery)。 现在我希望通过用一些默认值填充两个隐藏字段来提交表单, 我试图为这两个隐藏字段赋值,但没有成功,
请帮助我,这是我尝试过的,但无法为隐藏的文本字段赋值。
$(document).ready(function(){
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="red"){
$(".box").hide();
$(".red").show();
}
if($(this).attr("value")=="green"){
$(".box").hide();
$(".green").show();
}
if($(this).attr("value")=="blue"){
$(".box").hide();
$(".blue").show();
}
});
});
.box{
padding: 20px;
display: none;
margin-top: 20px;
border: 1px solid #000;
}
.red{ background: #ff0000; }
.green{ background: #00ff00; }
.blue{ background: #0000ff; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<label><input type="radio" name="colorRadio" value="red"> red</label>
<label><input type="radio" name="colorRadio" value="green"> green</label>
<label><input type="radio" name="colorRadio" value="blue"> blue</label>
</div>
<form id="myform">
<div class="red box">
<input type="text" >
</div>
<div class="green box"><input type="text" ></div>
<div class="blue box"><input type="text" ></div>
<input type="submit">
</form>
【问题讨论】:
-
你没有为这三个输入文本字段设置名称,并且你没有为这些赋值。
-
试试 Keith Wood jQuery 插件 - keith-wood.name/countdown.html
标签: javascript jquery html forms