本文實例講述了javascript動態創建鏈接的方法。分享給大家供大家參考。具體分析如下:
動態創建鏈接示例:
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>動態添加鏈接</title> <script type="text/javascript"> function AppendLink() {  var div = document.getElementById("divMain");  var linkTmp = document.createElement("a");  linkTmp.;  linkTmp.innerText = "百度";   //鏈接要使用innertText,不能使用value  div.appendChild(linkTmp); } </script></head><body> <div id="divMain"></div> <input type="button" value="添加鏈接" onclick="AppendLink()" /></body></html>希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答