HTML结构代码
<body> <input> <p>单击输入框获取焦点。</p> <span>请输入你的电话号码?</span> </body>
Java script代码
<script type="text/JavaScript"> let p=document.getElementsByTagName('input')[0]; console.log(p); let span=document.getElementsByTagName('span')[0]; console.log(span); p.onclick=function(){ span.style.display="block"; }; </script>
jQuery代码
<script type="text/JavaScript" src="./js/jquery-3.4.1.js"></script> <script type="text/JavaScript"> $(document).ready(function(){ $("input").bind("focus",function(){ $("span").show(); }); }); </script>