看板 Web_Design 關於我們 聯絡資訊
我想用 javascript 寫出一個超連結,例如這樣: <a href="http://www.google.com.tw/">Google@台灣</a> 當然不是直接用 document.write 來寫,因為那樣會過不了 W3C 校驗。 我用 google 找了一下資料,大致上寫了一個範例: <p id="test"> <script type="text/javascript"> tagA = document.createElement("a"); attrHREF = document.createAttribute("href"); attrHREF.nodeValue = "http://www.google.com.tw/"; tagA.setAttributeNode(attrHREF); attrTITLE = document.createAttribute("title"); attrTITLE.nodeValue = "測試文字"; tagA.setAttributeNode(attrTITLE); sometext = document.createTextNode("Google@台灣"); tagA.appendChild(sometext); place = document.getElementById("test"); place.appendChild(tagA); </script> </p> 這樣表現出來的效果應該是: <p id="test"> <a title="測試文字" href="http://www.google.com.tw/">Google@台灣</a> </p> 目前看到的資料是這樣,離目標只差一步了, 能不能不要 get element by id,而是直接在寫這段 script 的地方插入標籤? -- ╭─我的網站────────╮ │http://www.chweng.idv.tw/ │ │ 我的相簿、我的部落格 │ ╰─────────────╯ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.107.22 ※ 編輯: chweng 來自: 220.134.107.22 (12/01 13:48)