<lable id="lable1" onclick="col(1)">1</lable>
<lable id="lable2" onclick="col(2)">2</lable>
<lable id="lable3" onclick="col(3)">3</lable>
<script language="javascript">
function col(num)
{
for(i=1;i<6;i++)
{
if(i==num)
document.getElementById("lable"+i).backgroudcolor=Red;
else
document.getElementById("lable"+i).backgroudcolor=Black;
}
}
</script>可能有问题啊,自己再改改
<lable id="lable2" onclick="col(2)">2</lable>
<lable id="lable3" onclick="col(3)">3</lable>
<script language="javascript">
function col(num)
{
for(i=1;i<6;i++)
{
if(i==num)
document.getElementById("lable"+i).backgroudcolor=Red;
else
document.getElementById("lable"+i).backgroudcolor=Black;
}
}
</script>可能有问题啊,自己再改改
解决方案 »
- Extjs 4.1 grid分页问题
- javascript调用别的元素上的事件
- 如何在异步方式中给全局变量赋值(jquery相关)
- servelet向java中传值问题
- 如何用javascript获取当前时间的前13个月的字符串?
- 为什么我的Ajax在IE中OK,FF就全无反应?
- 想让jquery先获取iframe的宽和高,然后dialog再居中,我的代码问题在哪?
- JavaScript中可以进行实时显示吗?
- 关于客户端脚本向服务器提交变量的问题 大家谈谈自己的方法 好方法一定给分 不够再加!!!
- 如何知道网页里是否有某个对象?有多少个?
- 为什么方法体不执行,连action 都不走
- 为什么方法体不执行,连action 都不走
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var a=document.links;
for(var i=0;i<a.length;i++){
a[i].style.color="black";
a[i].onclick=change;
}
}
function change(){
var a=document.links;
for(var i=0;i<a.length;i++){
a[i].style.color="black";
a[i].onclick=change;
}
this.style.color="red";
}
window.onload=init;
</script>
</head><body>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
</body>
</html>
这样试试
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var a=document.links;
for(var i=0;i<a.length;i++){
a[i].style.color="black";
a[i].onclick=change;
}
}
function change(){
var a=document.links;
for(var i=0;i<a.length;i++){
a[i].style.color="black";
}
this.style.color="red";
shows(this);
}
function shows(a){
alert(a.href);
}
window.onload=init;
</script>
</head><body>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
</body>
</html>
额 把已有的事件放进change里试试 或者addEventListener和attachEvent
{
}
a:link{ /* 超链接正常状态下的样式 */
color:Red; /* 红色 */
text-decoration:none; /* 无下划线 */
}
a:visited{ /* 访问过的超链接 */
color:#000000; /* 黑色 */
text-decoration:none; /* 无下划线 */
}
a:hover{ /* 鼠标经过时的超链接 */
color:#FFFF00; /* 黄色 */
text-decoration:underline; /* 下划线 */
}你可以用JS 调用 CSS的CLASS 来变化不用颜色
<a name="ca" onclick="setClass1(this);">A1</a>
<a name="ca" onclick="setClass1(this);">A2</a>
<a name="ca" onclick="setClass1(this);">A3</a><script type="text/javascript">
function setClass1(obj) {
clearClass();
obj.style.color = "red";
}
function clearClass() {
var aList = document.getElementsByName("ca");
for (var i = 0, len = aList.length; i < len; i++) {
aList[i].removeAttribute("style");
}
}
</script>
<a id="a" href="#">1</a>
<a id="b" href="#">2</a>
<a id="c" href="#">3</a>
<a id="d" href="#">4</a>
<a id="e" href="#">5</a>
var a = document.getElementById("a");
a.onclick=function(){
this.style.color="red";
}
var b = document.getElementById("b");
b.onclick=function(){
a.style.color="blue";
}
<a id="b" href="#">2</a>
<a id="c" href="#">3</a>
<a id="d" href="#">4</a>
<a id="e" href="#">5</a>
var a = document.getElementById("a");
var b = document.getElementById("b");
var c = document.getElementById("c");
var d = document.getElementById("d");
var e = document.getElementById("e");
a.onclick=function(){
this.style.color="red";
b.style.color="blue";
c.style.color="blue";
d.style.color="blue";
e.style.color="blue";
}
b.onclick=function(){
this.style.color="red";
a.style.color="blue";
c.style.color="blue";
d.style.color="blue";
e.style.color="blue";
}
c.onclick=function(){
this.style.color="red";
a.style.color="blue";
b.style.color="blue";
d.style.color="blue";
e.style.color="blue";
}
d.onclick=function(){
this.style.color="red";
a.style.color="blue";
b.style.color="blue";
c.style.color="blue";
e.style.color="blue";
}
e.onclick=function(){
this.style.color="red";
a.style.color="blue";
b.style.color="blue";
c.style.color="blue";
d.style.color="blue";
}
var Par=obj.parentNode;
for(i=0;i<Par.childNodes.length;i++){Par.childNodes[i].className="black";}
obj.className="red";
}
$('#gj').removeClass("wrappedElement_w");
$('#gj').removeAttr('style');//本身是白色的
$('#gj').addClass("wrappedElement");//添加红色
$('#sb').addClass("wrappedElement_w");//其他的添加白色
$('#qt').addClass("wrappedElement_w");//同上我在3个A标签的onclick事件里写的这些,3个还可以 但我另一个页面有6个连接,那代码量就太大了,所以想找个方便的方法
<a name="ca" onclick="setClass1(this);">A1</a>
<a name="ca" onclick="setClass1(this);">A2</a>
<a name="ca" onclick="setClass1(this);">A3</a>
<script type="text/javascript">
function setClass1(obj) {
clearClass();
$(obj).addClass("bg_color");
}
function clearClass() {
$("a[name='ca']").each(function () {
$(this).removeClass("bg_color");
});
}
</script>
<a>A1</a>
<a>A2</a>
<a>A3</a>
<script type="text/javascript">
//如下代码也是可以的,建议给a标签加标识,否侧页面a标签多,就不容易控制了
$("a").click(function () {
clearClass();
$(this).addClass("bg_color");
});
function clearClass() {
$("a").each(function () {
$(this).removeClass("bg_color");
});
}
</script>
<style type="text/css">
.bg_color
{
cursor:pointer;
color:Red;
}
</style>