当然不行,style 是对象属性,无法直接设置!
L@_@K
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<div id="d1">Dynamic Style</div>
<script language="javascript">
d1.style.fontWeight = 'bold';
d1.style.fontSize = "20px";
</script>
</body>
</html>
L@_@K
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<div id="d1">Dynamic Style</div>
<script language="javascript">
d1.style.fontWeight = 'bold';
d1.style.fontSize = "20px";
</script>
</body>
</html>
那是标记中 style="font-weight:bold" 起滴作用!
只是想问看看能不能用什么方法直接 style='font-weight:bold;font-size:11px'
L@_@K
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<DIV STYLE="font-size:12pt" onmouseover="this.style.fontSize='20pt'" onmouseout="this.style.fontSize='12pt'">
鼠标移过,字体大小动态变换!
</DIV>
</body>
</html>
用 prototype.js 的 camelize()
把 font-size 转成 fontSize
然后 Object.extend(d1.style ,{'style集合'})
我自己先去试试,回头再来结贴 :D
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
<style type="text/css">
.divStyle1
{
font-size:12pt;
}
.divStyle2
{
font-size:20pt;
font-weight: bold;
color: red;
}
</style>
</head>
<body>
<DIV class='divStyle1' onmouseover="this.className='divStyle2';" onmouseout="this.className='divStyle1';">
鼠标移过,字体大小动态变换!
</DIV>
</body>
</html>
var s = param['style'];
var atts = {};
arr = s.split(";");
arr.each( function(e){
att = e.split(":");
atts[att[0].strip().camelize()] = att[1].strip();
})
Object.extend(returnElement.style, atts);
}