为什么我这段JS代码不起作用!! 一样不行。我甚至在页面中放一个BUTTON,在ONCLICK事件中写上执行SetColor('tRY','#fcfcf3','#fcfcf3','#ffff66','#ffff33'); ,还是不行,郁闷 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用cssthis.style.backgroundColor||this.className=""//設置css t[i].onmouseover=function(){ if(this.x!="1") {//this.style.backgroundColor=c; this.style.className="over"; alert(this.style.className); } }修改了下,在onmouseover事件中插入了一个alert用来显示设置的CSS是否成功,结果是正常的,可是颜色还是没变化 try:function SetColor(o,a,b,c,d){ //("表格名称","奇数行背景","偶数行背景","鼠hマ~ヌ諸w景","点炅后背景"); var t=document.getElementById(o).getElementsByTagName("TR"); for(var i=0;i<t.length;i++){ (function(){ var index=i; t[index].style.backgroundColor=(t[index].sectionRowIndex%2==0)?a:b; t[index].onclick=function(){ if(this.x!="1"){ this.x="1"; this.style.backgroundColor=d; }else{ this.x="0"; this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; } } t[index].onmouseover=function(){ if(this.x!="1"){ this.style.backgroundColor=c; status=this.sectionRowIndex; } } t[index].onmouseout=function(){ if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; } })(); }} 不用JS也能实现。<tr onmouseover="this.className='鼠标滑过的样式'" onmouseout="this.className='鼠标移走后的样式'"></tr>我曾经用到过,这个方法虽然有些笨,但还是行得通的,在IE、Firefox、Google Chroma、Opera下都没问题。 再解释下,这个函数本身并没有什么问题,因为我把这个函数用在一个非ASP生成的表格中时,是行的通的,只是对ASP生成的表格行没有起到作用。 是很奇怪,加个断点看一下用asp生成的tr有没有被getElementsByTagName("TR");取到吧? 取到了,看 status=this.sectionRowIndex;这句就是为了判断的,事实证明,当鼠标在行中划过时,状态栏里面确实是显示的行号还有,在这个ASP页面中这个函数没起作用,但是当将这个显示出来的页面的HTML保存为静态HTML时,又可以使用 已经用到js了,hehe 不过这个方法好,定义一下不同样式,便于统一修改 jquery 多简单$("#id").attr("background","xx"); 我主要是想和大家一起讨论讨论为什么对ASP生成的行没起到作用。。 唉,找到问题了,原来是CSS文件中对TD设置了padding和MARGIN属性造成的原因,不知道这跟backgroundColor属性有什么关系。真是麻烦 求助JS获得TD的值然后修改 JS数组问题 js删除cookie问题 如何用javascript比较两时间的大小 高手指点下 当我选中一个radio,出现一个文本,当我选中另一个radio时有出现另外一个文本,怎么实现,谢谢 如何设置按钮失效和定时恢复 关于JS调用控件打印的问题,小弟在线等,急呀 求一个JAVASCRIPT 关于select的简单问题急...... cookie是否只能进行自读(写)操作??当前文件可以读其它文件所写cookiek吗?? 请问用什么方法可以弹出窗口? [原创]提升javascript程序字符串操作的性能
this.style.backgroundColor
|
|
this.className=""//設置css
if(this.x!="1")
{//this.style.backgroundColor=c;
this.style.className="over";
alert(this.style.className);
}
}修改了下,在onmouseover事件中插入了一个alert用来显示设置的CSS是否成功,结果是正常的,可是颜色还是没变化
function SetColor(o,a,b,c,d){
//("表格名称","奇数行背景","偶数行背景","鼠hマ~ヌ諸w景","点炅后背景");
var t=document.getElementById(o).getElementsByTagName("TR");
for(var i=0;i<t.length;i++){
(function(){
var index=i;
t[index].style.backgroundColor=(t[index].sectionRowIndex%2==0)?a:b;
t[index].onclick=function(){
if(this.x!="1"){
this.x="1";
this.style.backgroundColor=d;
}else{
this.x="0";
this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
}
}
t[index].onmouseover=function(){
if(this.x!="1"){
this.style.backgroundColor=c;
status=this.sectionRowIndex;
}
}
t[index].onmouseout=function(){
if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
}
})();
}
}
<tr onmouseover="this.className='鼠标滑过的样式'" onmouseout="this.className='鼠标移走后的样式'"></tr>
我曾经用到过,这个方法虽然有些笨,但还是行得通的,在IE、Firefox、Google Chroma、Opera下都没问题。
只是对ASP生成的表格行没有起到作用。
这句就是为了判断的,事实证明,当鼠标在行中划过时,状态栏里面确实是显示的行号
还有,在这个ASP页面中这个函数没起作用,但是当将这个显示出来的页面的HTML保存为静态HTML时,又可以使用
已经用到js了,hehe 不过这个方法好,定义一下不同样式,便于统一修改
$("#id").attr("background","xx");