【发布时间】:2016-05-05 06:32:41
【问题描述】:
我有一个类为 footer-contact 的 div,在该 div 中,我有几个 input 和 textarea 元素。我想清空他们的文字。我尝试使用以下选择器,但它不起作用。我做错了什么?
$(".footer-contact input[type=text] textarea").val('');
【问题讨论】:
我有一个类为 footer-contact 的 div,在该 div 中,我有几个 input 和 textarea 元素。我想清空他们的文字。我尝试使用以下选择器,但它不起作用。我做错了什么?
$(".footer-contact input[type=text] textarea").val('');
【问题讨论】:
您可以使用Multiple Selector (“selector1, selector2, selectorN”)
$(".footer-contact input[type=text], .footer-contact textarea").each(function(){
this.value = "";
});
【讨论】:
$(".footer-contact,input[type=text],textarea").val('');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' class='footer-contact' value='asdas'>
<input type='text' value='asdas'>
<textarea>asdas</textarea>
【讨论】:
textarea 元素还是只选择 footer-contact 中的元素?
这对我有用
var val1 = document.getElementsByTagName("input")[4];
var val2 = document.getElementsByTagName("input")[5];
$([val2, val1]).keyup(() => { }
【讨论】: