Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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 - Fatal编程技术网

Javascript 清除表单输入(某些控件除外)

Javascript 清除表单输入(某些控件除外),javascript,jquery,Javascript,Jquery,我有一个名为pBody的面板,我可以使用这些代码清除它的控件。 清除所有文本框,取消选中单选按钮和复选框: $('#pBody input').val(''); 仅清除文本框: $("#pBody").find("input[type=text]").val(''); 或 但在单击“清除”按钮后,我希望选中一些单选按钮,例如组中的第一个单选按钮。 提前感谢。您可以使用input[type=radio]:first选择器选择列表中的第一个单选按钮。 或者,如果您希望选中每个GROUP fir

我有一个名为pBody的面板,我可以使用这些代码清除它的控件。 清除所有文本框,取消选中单选按钮和复选框:

$('#pBody input').val('');
仅清除文本框:

$("#pBody").find("input[type=text]").val(''); 

但在单击“清除”按钮后,我希望选中一些单选按钮,例如组中的第一个单选按钮。
提前感谢。

您可以使用
input[type=radio]:first
选择器选择列表中的第一个单选按钮。
或者,如果您希望选中每个GROUP first单选按钮,您可以使用

$('element').each(function(){
    $('input[type=radio]:first', this).attr('checked', true);
});

对于默认选中第一个单选按钮,您可以使用以下代码

$('#pBody').find('input:radio').first().prop({checked:true});

和复选框使用

$('#pBody').find('input:checkbox').first().prop({checked:true});


您只需将类应用于单选按钮,然后在选择器中应用
:not
,以获取其余控件并进行进一步处理。您可以在代码中显示它吗?
$(“输入:not(.test)”).css(“背景色”,“黄色”)
这里的类名是
test
。我确信您的代码是正确的,但是在这个代码$(''#pBody input').val('')之后它就不起作用了;我在这样的函数中使用了主题:$('#pBody input').val(''$('#pBody').find('input:radio').first().attr({checked:true});你试过道具价值观吗。。。我也遇到了同样的问题,所以我被给予了“attr”和“prop”
$('#pBody').find('input:radio').first().attr({checked:true});
$('#pBody').find('input:checkbox').first().prop({checked:true});
$('#pBody').find('input:checkbox').first().attr({checked:true});