改变单个链接背景颜色怎么写 <a style="background-color:red">a</a> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.直接在该标签后面定义样式:<a style="background-color:red"></a>。2.用CSS中的类:.example{ background-color:red;}<a class="example"></a>3.用CSS中元素直接定义样式方式:#example{ background-color:red;}<a id="example"></a> 既然在js里提问 就用js来设定吧.首先找到这个<a>标签 如果有id则用document.getElementById来找 如果没有但知道DOM位置, getElementsByTagName[n]来找到此a结点 然后.style.backgroundColor="red";即可<html> <head> <title>change <a>'s backgound-color</title> <script type="text/javascript"> function change1(){ var _a = document.getElementById("test"); _a.style.backgroundColor="red"; } function change2(){ var _a = document.getElementsByTagName("a")[1];// _a.style.backgroundColor="green"; } /*以上两种方法通过不同方式找到了同一元素*/ var num=1; function change(){ if(num%2==0){ change1(); }else{ change2(); } num++; } </script> </head> <body> <a href="www.sina.com.cn">Let's go to SINA</a> <a id="test" href="www.baidu.com">Let's go to BAIDU</a> <button onclick="change()">change <a>'s color</button> </body></html> JavaScript实现时钟, 大神进来帮个忙 javascript中的二维数组 WEB的TAB页问题:在网页中的某一TAB页操作,成功后返回时如何才能定位到刚才操作的TAB页? 在线等待,有关js文件调用的问题 点击radio按钮, 用正则表达式怎么确定textbox里面是一个有效的文件名???谢谢。 怎样使表单的文本框内容不被清空? 请问哪里有能够丰富的格式化文本的控件下载?50分 如何取得N个单元格的内容? 请问如何设置弹出窗口的输入法?? 求一正则表达式 限制以英文發表文章(全型字列入中文字範圍) 如何用js增加网站的内链
<a style="background-color:red"></a>。
2.用CSS中的类:.example
{
background-color:red;
}
<a class="example"></a>3.用CSS中元素直接定义样式方式:#example
{
background-color:red;
}
<a id="example"></a>
<html>
<head>
<title>change <a>'s backgound-color</title>
<script type="text/javascript">
function change1(){
var _a = document.getElementById("test");
_a.style.backgroundColor="red";
}
function change2(){
var _a = document.getElementsByTagName("a")[1];//
_a.style.backgroundColor="green";
}
/*以上两种方法通过不同方式找到了同一元素*/
var num=1;
function change(){
if(num%2==0){
change1();
}else{
change2();
}
num++;
}
</script>
</head>
<body>
<a href="www.sina.com.cn">Let's go to SINA</a>
<a id="test" href="www.baidu.com">Let's go to BAIDU</a>
<button onclick="change()">change <a>'s color</button>
</body>
</html>