我只能得到input标签,但我也希望得到textarea标签.我怎样才能做到这一点?
<div class="common-div">
<input type="text" name="confirm-pwd"/>
<textarea cols="150" rows="5"></textarea>
</div>
<script>
$(".common-div input").each(function() {}):
</script>
Run Code Online (Sandbox Code Playgroud)
您可以在逗号后枚举它们:
$(".common-div input, .common-div textarea").each(function(){}):
Run Code Online (Sandbox Code Playgroud)
或者,正如@epascarello在注释中指出的那样,为要使用jQuery修改的元素使用公共类名.