我想通过DOM+javascript来修改一个标签的内联样式
我们知道每个标签都有style属性(内联样式),我是否可以这样,把a标签的颜色变红?<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function onMouseDown()
{var x=document.getElementById("aaa").style="color:red";
}
</script>
</head><body>
<a href="#" id="aaa">aa</a>
<input type="button" onmousedown="onMouseDown()">
</body>
</html>
我们知道每个标签都有style属性(内联样式),我是否可以这样,把a标签的颜色变红?<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function onMouseDown()
{var x=document.getElementById("aaa").style="color:red";
}
</script>
</head><body>
<a href="#" id="aaa">aa</a>
<input type="button" onmousedown="onMouseDown()">
</body>
</html>
function onMouseDown()
{document.getElementById("aaa").style="color:red";
}
再:document.getElementById("aaa").className='class1';
document.getElementById("aaa").style.color = 'red';
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function onMouseDown()
{
var x=document.getElementById("aaa").style.color="red";
alert(x)
}
</script>
</head><body>
<a href="#" id="aaa">aa</a>
<input type="button" onmousedown="onMouseDown()">
</body>
</html>直接 document.getElementById("aaa").style.color="red" 就okhttp://www.w3school.com.cn/b.asp
楼主可以看下 html dom 及DHTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="http://s.syyx.com/nycs/js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(":button").click(function(){
alert("11111");
$("#aaa").css({"color":"red" });
})
})
</script>
</head><body>
<a href="#" id="aaa" style=" color:#F0F;">我要变颜色</a>
<input type="button" value="有本事点我啊"></input>
</body>
</html>