JS添加父节点的方法。

时间:2023-12-15 09:53:56
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><html>
<title>Test</title>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
</head>
<body>
<select id="mySelect">
<option value="1">First</option>
</select>
<script type="text/javascript">
/* 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);
*/
$("#mySelect").wrap("<span></span>");
$("span").css("border","1px solid red");
</script>
</body>
</html>