获取元素js点击tab,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">dt猫</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> <style>.label {cursor:pointer}</style> <input type="text" id="textbox" size = "30" name="chaxinmd" /> <div id="sp"> <span class="label">JS特效</span> <span class="label">C++</span> <span class="label">SQL</span> <span class="label">dt猫</span> </div> <script type="text/javascript"> /*spans=docuemnt.getElementById("sp").getElementsByTagName("span");*/ spans=document.getElementById("sp").childNodes; for(i=0;i<spans.length;i++) {if(spans[i].className=="label") { spans[i].onclick=function() { document.getElementById('textbox').value=this.innerHTML; }}} </script>

 

posted @ 2020-07-23 15:29  南瓜小园  阅读(626)  评论(0编辑  收藏  举报