日期:2014-05-16 浏览次数:20444 次
elem.insertAdjacentHTML("beforeBegin","<span style=\"border: 1px solid red\">*</span>");
------解决方案--------------------
elem.insertAdjacentHTML("beforeBegin", "<span style=\"border: 1px solid red\">"); elem.insertAdjacentHTML("afterend", "</span>");
------解决方案--------------------
<!doctype html> <html> <head> <title>Test</title> </head> <body> <select> <option value="1">First</option> </select> <script> var sel = document.getElementsByTagName("select")[0], _sel = sel.cloneNode(true), span = document.createElement("span"); span.style.border = "1px solid red"; //span.style.cssText = "border: 1px solid red"; span.appendChild(_sel); sel.parentNode.replaceChild(span, sel); </script> </body> </html>