html 点击按钮清空输入框内容

时间:2024-02-15 14:04:59

 

完整代码:

 

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 </head>
 5 
 6 <body>
 7 <div style="font-size:16px;float:left ;">
 8     <label class="text">内容
 9         <input  type="text" id="key" name="key"
10                placeholder="请输入"></label>
11     <button  type="button" onclick="clearText()">清空</button>
12 </div>
13 </body>
14 
15 {#地址根据实际的路径填写#}
16 <script type="text/javascript" src="xxxxx/js/jquery.min.js"></script>
17     <script type="text/javascript" language="javascript">
18         function clearText() {
19             $(\'.text input\').val(\'\');
20         }
21     </script>
22 
23 </html>