删除与单选按钮
下面的代码本身在输入表单中的值删除与单选按钮
<Input type = "radio"> <Input type = "text" name = "nominal" value = "1000">
我想用单选按钮删除输入形式的价值,怎么样?
请帮我
感谢
下面是一个例子代码
<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>
太好了,谢谢大师 –
欢迎您! –
但是取消后再次填充的内容呢? –
你可以这样做以下(无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;
}
}
<input type = "radio" id="myRadio" onclick="handleClick(event);" />
<input type = "text" id="txtNominal" name = "nominal" value = "1000">
解决方案使用复选框
<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>
如何取消选中返回值,而不是确定的值? 不是这样的:$('#nominal')。 Val(1000); –
那么你想要取代什么价值? –
复位一样的形式? – Swellar
是的,真的很喜欢 你能帮我吗? –
为什么你有一个单选按钮?他们应该用于小组。 – nnnnnn