Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击时如何从表单字段中删除文本输入?_Javascript_Jquery_Html_Forms - Fatal编程技术网

Javascript 单击时如何从表单字段中删除文本输入?

Javascript 单击时如何从表单字段中删除文本输入?,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我有一组单选按钮和一个文本输入字段。当我点击文本输入时,单选按钮将被JavaScript取消选中,但当我在表单字段中键入内容,然后重新选择单选按钮时,我无法删除文本。这是我到目前为止的代码,如果有人能帮助我在我选择一个我知道我关闭的收音机时清除所有输入的文本框 <input type="radio" id="radio1" name="radios" checked> <label for="radio1">$10</label> <input ty

我有一组单选按钮和一个文本输入字段。当我点击文本输入时,单选按钮将被JavaScript取消选中,但当我在表单字段中键入内容,然后重新选择单选按钮时,我无法删除文本。这是我到目前为止的代码,如果有人能帮助我在我选择一个我知道我关闭的收音机时清除所有输入的文本框

<input type="radio" id="radio1" name="radios"   checked>
<label for="radio1">$10</label>
<input type="radio" id="radio2" name="radios" >
<label for="radio2">$25</label>
<input type="radio" id="radio3" name="radios"  >
<label for="radio3">$50</label>
<input type="radio" id="radio4" name="radios" >
<label for="radio4">$100</label>
<input type="text" id="textInput">
<script>
<!-- to remove radio on text input click-->
$('#textInput').click(function () {
    $.each($('input[type=radio]'), function () {
         $(this).removeAttr("checked");
});
});
<!-- to remove text on text radio button click-->
$('input[type=radio]').click(function () {
    $.each($('#textInput'), function () {
        $(this).removeAttr("input");
});
});
</script>

$10
$25
$50
$100
$('#textInput')。单击(函数(){
$。每个($('input[type=radio]')、函数(){
$(此).removeAttr(“选中”);
});
});
$('input[type=radio]')。单击(函数(){
$。每个($('#textInput'),函数(){
$(此).removeAttr(“输入”);
});
});

只需使用
val()
删除它们的值即可<代码>输入不是属性,而是标记名

$.each($('#textInput'), function () {
    $(this).val("");
只需使用.val(),也不需要
$。每个

$('input[type=radio]').click(function () {
    $('#textInput').val('');            
});
您必须使用
.val(“”)
将文本框值设置为空

试试这个

$('#textInput').each(function () {
   $(this).val("");
});