在线等~如何用js给指定id添加样式?
<!DOCTYPEHTML><html><head><metacharset="UTF-8"/><title>last.html</title><style></styl...
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>last.html</title>
<style>
</style>
<script type="text/javascript">
Date.prototype.diff = function (date)
{
return (this.getTime () - date.getTime ()) / (24 * 60 * 60 * 1000);
}
onload = function ()
{
var now = new Date ('2015/02/19 00:00:00');
var date = new Date ();
var diff = now.diff (date);
document.getElementById ('end2').innerHTML = Math.floor (diff);
}
</script>
</head>
<body>
距过年
<span id="end2"></span>天
</body>
</html>
想给span 添加样式color:#a00000; font-size:20px; font-weight:700; 怎么做? 展开
<html>
<head>
<meta charset="UTF-8" />
<title>last.html</title>
<style>
</style>
<script type="text/javascript">
Date.prototype.diff = function (date)
{
return (this.getTime () - date.getTime ()) / (24 * 60 * 60 * 1000);
}
onload = function ()
{
var now = new Date ('2015/02/19 00:00:00');
var date = new Date ();
var diff = now.diff (date);
document.getElementById ('end2').innerHTML = Math.floor (diff);
}
</script>
</head>
<body>
距过年
<span id="end2"></span>天
</body>
</html>
想给span 添加样式color:#a00000; font-size:20px; font-weight:700; 怎么做? 展开
2个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>last.html</title>
<style type="text/css">
#end2{
color:#a00000;
font-size:20px;
font-weight:700;
}
</style>
<script type="text/javascript">
Date.prototype.diff = function (date)
{
return (this.getTime () - date.getTime ()) / (24 * 60 * 60 * 1000);
}
onload = function ()
{
var now = new Date ('2015/02/19 00:00:00');
var date = new Date ();
var diff = now.diff (date);
document.getElementById ('end2').innerHTML = Math.floor (diff);
}
</script>
</head>
<body>
距过年
<span id="end2"></span> 天
</body>
</html>
追问
直接加么,,,我刚才试怎么不行,把你的复制下来就行了,,无语,,给分了。
追答
或者 <span id="end2" style="color:#a00000; font-size:20px; font-weight:700;
"></span> 亦可
展开全部
$("#end2").css({"color":"#a00000"},{"fontSize":"20px"},{"fontWeight":"700"});
追问
不灵,放到什么 地方?
追答
你有没有引入jquery啊
如果没有就得用JS
var obj=document.getElementById("#end2");\
obj.style.color="#a00000";
obj.style.fontSize="20px";
obj.style.fontWeight="700";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询