以下代码本身
<Input type = "radio"> <Input type = "text" name = "nominal" value = "1000">
我想用单选按钮删除输入表单的值,怎么做?
请帮帮我
感谢
答案 0 :(得分:0)
这是一个示例代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#radio').change(function(){
$('#nominal').val('');
});
});
</script>
<div>
<input id="radio" type= "radio">
<input id="nominal" type= "text" name="nominal" value="1000">
</div>
答案 1 :(得分:0)
您可以执行以下操作(无jQuery
):
var isChecked = true;
function handleClick(e) {
if(isChecked){
document.getElementById('txtNominal').value = '';
document.getElementById('myRadio').checked = true;
isChecked = false;
}
else{
document.getElementById('txtNominal').value = '1000';
document.getElementById('myRadio').checked = false;
isChecked = true;
}
}
&#13;
<input type = "radio" id="myRadio" onclick="handleClick(event);" />
<input type = "text" id="txtNominal" name = "nominal" value = "1000">
&#13;
答案 2 :(得分:0)
使用复选框解决方案
<script type="text/javascript">
$(document).ready(function(){
$('#checkbox').change(function() {
if($('#checkbox').is(':checked')) {
$('#nominal').val('');
} else {
$('#nominal').val(1000);
}
});
});
</script>
<div>
<input id="checkbox" type= "checkbox">
<input id="nominal" type= "text" name="nominal" value="1000">
</div>