javascript中創(chuàng)建一個(gè)按鈕
var body= document.body; ? ? ? ? ? ?
? var btn = document.createElement("input"); ?
? btn.setAttribute("type", "text"); ?
? btn.setAttribute("name", "q"); ?
? btn.setAttribute("value", "使用setAttribute"); ?
? btn.setAttribute("onclick", "javascript:alert('This is a text!');"); ? ? ?
? body.appendChild(btn); ?
畫(huà)橫線當(dāng)中為甚alert括號(hào)里的內(nèi)容只能用單影號(hào)
2016-04-17
"javascript:alert('This is a text!');" ?在外面已經(jīng)有了一對(duì)雙引號(hào)(為了防止 引號(hào)匹配錯(cuò)誤; 單引號(hào)與雙引號(hào)交叉使用)