gpt4 book ai didi

javascript - 如何在html中的不同部门调用一个id

转载 作者:行者123 更新时间:2023-11-30 10:15:36 24 4
gpt4 key购买 nike

我使用的是 html5 单页模板....我有 3 个文本框、一个文本区域和一个清除按钮....3 个文本框和清除按钮在同一个 div 中....文本区域在另一个 div 中...我想通过单击清除按钮清除所有文本框,,,,在我的代码中,仅清除 3 个文本框...第 4 个文本框未清除..

<div>
<input name="subject" type="text" id="subject" placeholder="Your Subject">
<input name="email" type="text" id="email" placeholder="Your Email"">
<div>
<button type="reset" id="reset" value="Clear" >clear</button>
</div>
</div>
<div>
<textarea name="message" rows="10" class="form-control" id="message" >
<textarea>
</div>

我想通过这个清除按钮清除所有文本框请给出解决这个问题的方法....我是初学者!

谢谢你

最佳答案

您需要在表单标签内提供所有输入字段

<form>
<div>
<input name="subject" type="text" id="subject" placeholder="Your Subject">
<input name="email" type="text" id="email" placeholder="Your Email">
<div>
<textarea name="message" rows="10" class="form-control" id="message" > </textarea>
</div>
<div>
<button type="reset" id="reset" value="Clear" >clear</button> </div>
</div>
</form>

来自此引用:http://www.w3.org/TR/html5/forms.html#attr-button-type-reset-state

Reset Button If the element has a form owner and the element's Document is fully active, the element must reset the form owner. ... The form attribute is used to explicitly associate the button element with its form owner.

关于javascript - 如何在html中的不同部门调用一个id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23927589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com