本文实例讲述了JavaScript动态修改网页元素内容的方法。分享给大家供大家参考。具体分析如下:
下面的JS代码当用户点击提交按钮后,通过元素的textContent或者innerHTML动态指定元素的内容
<script type="text/javascript"> function showCard() { var message = document.getElementById("CCN").value; var element = document.getElementById("mycreditcardnumber"); element.textContent = message; //for Firefox element.innerHTML = message; //for IE (why can't we all just get along?) return true; } </script> <form name="dynamic" method="get"> <span>Enter Your Credit Card Number:</span> <input type="text" id="CCN" name="CCN" value="CCN" /> <input type="button" value="submit" onclick="showCard()" /> </form> <p>Verify your Credit Card Number: <span id="mycreditcardnumber">0000-00-0000-00 </span> </p>
希望本文所述对大家的javascript程序设计有所帮助。