日期:2014-05-16 浏览次数:20294 次
保存在这里,方便自己以后查看 (⊙_⊙) ╮(╯▽╰)╭
?
javascript 和 jQuery 两种方法:
$(window).load(function() { createSuspendedLinkByJavaScript(); createSuspendedLinkByjQuery(); }); function createSuspendedLinkByJavaScript() { var jsDiv = document.createElement("div"); jsDiv.setAttribute("id", "jsDiv"); var googleLink = document.createElement("a"); googleLink.setAttribute("target", "_blank"); googleLink.setAttribute("href", "http://www.google.com"); googleLink.appendChild(document.createTextNode("Google")); var baiduLink = document.createElement("a"); baiduLink.setAttribute("target", "_blank"); baiduLink.setAttribute("href", "http://www.baidu.com"); baiduLink.appendChild(document.createTextNode("Baidu")); jsDiv.appendChild(googleLink); jsDiv.appendChild(document.createTextNode(" | ")); jsDiv.appendChild(baiduLink); document.body.appendChild(jsDiv); } function createSuspendedLinkByjQuery() { var jQueryDiv = "<div id='jQueryDiv'>" + "<a target='_blank' href='http://www.google.com'>Google</a>" + "<span> | </span>" + "<a target='_blank' href='http://www.baidu.com'>Baidu</a>" + "</div>"; $(document.body).append(jQueryDiv); }