我希望在单选按钮选中时显示ptext,并在另一个单选按钮处于活动状态但不工作时隐藏。
这是我的密码:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<input id="postageyes" name="type" value="Paint" type="radio">Paint
<br>
<input id="postageno" name="type" value="Sculpture" type="radio">Sculpture
<br>
<input id="postageno" name="type" value="calligraphy" type="radio">calligraphy
<br>
<input id="stext" name="type" value="type" type="text"><br>
<input id="ctext" name="type" value="type" type="text"><br>
<input id="ptext" name="type" value="type" type="text">
<script type="text/javascript">
$('input:radio[name="postage"]').change(function() {
if ($(this).val() == 'Paint') {
$("#ptext").show();
} else {
$("#ptext").hide();
}
});
</script>
</body>
</html>发布于 2016-06-06 17:39:11
您有两个主要的问题:
id的值应该是唯一的。input作为postage的name。ptext。将name更改为postage
<input id="postageyes" name="postage" value="Paint" type="radio">Paint
<br>
<input id="postageno1" name="postage" value="Sculpture" type="radio">Sculpture
<br>
<input id="postageno2" name="postage" value="calligraphy" type="radio">calligraphy
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="postageyes" name="postage" value="Paint" type="radio">Paint
<br>
<input id="postageno1" name="postage" value="Sculpture" type="radio">Sculpture
<br>
<input id="postageno2" name="postage" value="calligraphy" type="radio">calligraphy
<br>
<input id="stext" name="type" value="type" type="text"><br>
<input id="ctext" name="type" value="type" type="text"><br>
<input id="ptext" name="type" value="type" type="text">
<script type="text/javascript">
$("#ptext").hide();
$('input:radio[name="postage"]').change(function() {
if ($(this).val() == 'Paint') {
$("#ptext").show();
} else {
$("#ptext").hide();
}
});
</script>
另外,在加载文档时最好将其隐藏起来。参见上面的示例。
发布于 2016-06-06 17:41:07
您必须在jQuery中传递错误的单选按钮名,请检查下面的代码好吗?
<script type="text/javascript">
$('input:radio[name="type"]').change(function() {
if ($(this).val() == 'Paint') {
$("#ptext").show();
} else {
$("#ptext").hide();
}
});
</script>发布于 2016-06-06 17:46:43
html --修复只在名称属性中,因为html中写的是“类型”,而不是“邮资”
<input id="postageyes" name="postage" value="Paint" type="radio">Paint
<br>
<input id="postageno" name="postage" value="Sculpture" type="radio">Sculpture
<br>
<input id="postageno" name="postage" value="calligraphy" type="radio">calligraphy
<br>
<input id="stext" name="type" value="type" type="text"><br>
<input id="ctext" name="type" value="type" type="text"><br>
<input id="ptext" name="type" value="type" type="text" style="display:none">javascript -javascript如果工作,我只会给您推荐,并且是,使用文档就绪
$(document).ready(function() {
$('input:radio[name="postage"]').change(function() {
if ($(this).val() == 'Paint') {
$("#ptext").show();
} else {
$("#ptext").hide();
}
});
});https://stackoverflow.com/questions/37663563
复制相似问题