제 질문은 onMouseover, onMouseout, onMousedown, onClick 테이블 행입니다. 어떤 자바 스크립트 사용자 정의 함수를 호출합니다.HTML + javascript 마우스 오버, mouseout, onclick이 파이어 폭스에서 작동하지 않음
onMouseover --- 배경색이 변경되어야합니다. onMouseout --- 원본 색상으로 재설정 onClick --- 첫 번째 열 확인란/라디오 버튼을 설정하고 배경색을 변경해야합니다. onMousedown --- 배경색이 변경되어야합니다.
HTML에서 내 코드입니다 : - <tr onMouseOver="hover(this)" onMouseOut="hover_out(this)" onMouseDown="get_first_state(this)" onClick="checkit(this)" >
와 자바 스크립트의 방법은 다음과 같습니다 -
var에 first_state = 거짓;
var oldcol = '#ffffff'; var oldcol_cellarray = new Array();
함수 호버 (요소) {
if (! element) element = this;
while (element.tagName != 'TR') {
element = element.parentNode;
}
if (element.style.fontWeight != 'bold') {
for (var i = 0; i<element.cells.length; i++) {
if (element.cells[i].className != "no_hover") {
oldcol_cellarray[i] = element.cells[i].style.backgroundColor;
element.cells[i].style.backgroundColor='#e6f6f6';
}
}
}
}
// -------------------------- -------------------------------------------------- -------------------
함수 hover_out (요소) {
if (! element) element = this;
while (element.tagName != 'TR') {
element = element.parentNode;
}
if (element.style.fontWeight != 'bold') {
for (var i = 0; i<element.cells.length; i++) {
if (element.cells[i].className != "no_hover") {
if (typeof oldcol_cellarray != undefined) {
element.cells[i].style.backgroundColor=oldcol_cellarray[i];
} else {
element.cells[i].style.backgroundColor='#ffffff';
}
//var oldcol_cellarray = new Array();
}
}
}
}
,// --------------------------------------------- --------------------------------------------------
함수 get_first_state (요소) {
while (element.tagName != 'TR') {
element = element.parentNode;
}
first_state = element.cells[0].firstChild.checked;
}
// -------------------------- -------------------------------------------------- -------------------
function checkit (element) {
IE 예상대로 515,while (element.tagName != 'TR') {
element = element.parentNode;
}
if (element.cells[0].firstChild.type == 'radio') {
var typ = 0;
} else if (element.cells[0].firstChild.type == 'checkbox') {
typ = 1;
}
if (element.cells[0].firstChild.checked == true && typ == 1) {
if (element.cells[0].firstChild.checked == first_state) {
element.cells[0].firstChild.checked = false;
}
set_rowstyle(element, element.cells[0].firstChild.checked);
} else {
if (typ == 0 || element.cells[0].firstChild.checked == first_state) {
element.cells[0].firstChild.checked = true;
}
set_rowstyle(element, element.cells[0].firstChild.checked);
}
if (typ == 0) {
var table = element.parentNode;
if (table.tagName != "TABLE") {
table = table.parentNode;
}
if (table.tagName == "TABLE") {
table=table.tBodies[0].rows;
//var table = document.getElementById("js_tb").tBodies[0].rows;
for (var i = 1; i< table.length; i++) {
if (table[i].cells[0].firstChild.checked == true && table[i] != element) {
table[i].cells[0].firstChild.checked = false;
}
if (table[i].cells[0].firstChild.checked == false) {
set_rowstyle(table[i], false);
}
}
}
}
}
함수 set_rowstyle (R상의) {
if (on == true) {
for (var i =0; i < r.cells.length; i++) {
r.style.fontWeight = 'bold';
r.cells[i].style.backgroundColor = '#f2f2c2';
}
} else {
for (i =0; i < r.cells.length; i++) {
r.style.fontWeight = 'normal';
r.cells[i].style.backgroundColor = '#ffffff';
}
}
}
그것은 작동된다.
하지만 파이어 폭스에 와서 나는 많은 코딩을 한 후에 결과물을 보면서 놀랐다.
Firefox의 경우 : - onMouseOver가 예상대로 작동합니다. 해당 특정 행의 색상 변경.
onClick - 배경색을 영구히 설정합니다. 다른 행에 대해서는 onmouseover를 수행합니다. 클릭 한 이전 행 색상은 흰색으로 재설정되지 않습니다.- 예상대로 아님
onclick on 2 rows .. 두 행의 배경이 설정됩니다. 최신 행 색상 만 설정해야합니다. 이전에 선택한 다른 행을 다시 설정해야합니다. 예기치 않은 것 같습니다. 즉 모든 행을 클릭하면 모든 배경색이 변경됩니다.
이벤트를 클릭해도 표시됩니다. 첫 번째 열, 즉 라디오 버튼 또는 체크 박스가 설정되지 않았습니다.
Firefox에서이 문제를 해결하는 데 도움을주세요. 내 코드를 어디에서 변경해야하는지 알려주세요 ...
미리 감사드립니다 !!
Firebug (http://getfirebug.com/)를 사용하여 자바 스크립트를 디버그하십시오. –