js如何实现点击标签文字在input文本框自动输入,下面给出具体实现代码。
<style>.label {cursor:pointer}</style> <input type="text" id="textbox" size = "30" name="chaxinmd" /> <span class="label">JS特效</span> <span class="label">C++</span> <span class="label">SQL</span> <span class="label">青华互联</span> <script type="text/javascript"> spans=document.getElementsByTagName("span"); for(i=0;i<spans.length;i++) {if(spans[i].className=="label") { spans[i].onclick=function() { document.getElementById('textbox').value=this.innerHTML; }}} </script>
示例截图:
扫描二维码手机查看该文章
文章引用:https://www.qinghuahulian.com/news/webzhishi/1345.html