Herlp与Firefox [英] Herlp with Firefox
问题描述
嗨!
这是'在学校的培训案例。该函数将在IE中为表格设置动画:
函数chgColor(){
var thistag,parenttag;
thistag = window.event.srcElement.tagName;
if(thistag ==" TD"){
document.all(window.event .srcElement.sourceIndex)。 bgColor ="#3280ff";
有谁可以给我这个在Firefox上工作所需的改变吗?
谢谢:-)
Krij写道:
Here''在学校的培训案例。该功能将在IE中动画
a表格单元格:
函数chgColor(){
var thistag,parenttag;
thistag = window.event.srcElement.tagName;
if(thistag ==" TD"){
document.all(window.event。 srcElement.sourceIndex)。 bgColor ="#3280ff";
任何可以给我改变的人都可以在这个工作中使用
Firefox?
并非没有看到如何调用此函数。
Richard。
对不起,这就是整件事:
< html>< head>< title> JavaScript课程工作示例< / title>
< script language =" javascript">
<! -
function chgColor(){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag ==" TD"){
文件。所有(window.event.srcElement.sourceIndex)。 bgColor ="#3280ff";
}
}
function chgBack(){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag ==" TD"){
document 。所有(window.event.srcElement.sourceIndex)。 bgColor ="#c0c0c0";
}
}
// - >< / script>< / head>
< body onmouseover =" chgColor()"的onmouseout = QUOT; chgBack()"字体
face =" verdana"大小= QUOT; 3英寸COLOR ="#000000">
< center>
< table border =" 5" BORDERCOLOR ="#006400" width =" 30%">
< tr>
< td> MAY< / td>< td>& nbsp;< / td>< td>& nbsp;< / td>< td>& nbsp;< / td>
< / tr>
< ; tr>
< td>& nbsp;< / td>< td> NOT< / td>< td>& nbsp;< / td>< td> & nbsp;< / td>
< / tr>
< tr>
< td>& nbsp; < / td>< td>& nbsp;< / td>< td> WORK< / td>< td>& nbsp;< / td>
< / tr>
< tr>
< td>& nbsp;< / td>< td>& nbsp;< / td>< ; td>& nbsp;< / td>< td> IN< / td>
< / tr>
< tr>
< td> FIREFOX< / td>< td>& nbsp;< / td>< td>& nbsp;< / td>< td>& nbsp;< / td>
< / tr>< / table>
感谢您的回答:-)
Richard Cornford skrev:
Krij写道:
这是'在学校的培训案例。该功能将在IE中动画
a表格单元格:
函数chgColor(){
var thistag,parenttag;
thistag = window.event.srcElement.tagName;
if(thistag ==" TD"){
document.all(window.event。 srcElement.sourceIndex)。 bgColor ="#3280ff";
任何可以给我改变的人都可以在这个工作中使用
Firefox?
并非没有看到如何调用此函数。
Richard。
Krij写道:
< snip>
< script language =" javascript">
不推荐使用language属性,并且
有效HTML 4中需要type属性,并且使用它会使语言属性变得多余: -
< script type =" text / javascript">
<! -
这种隐藏旧浏览器的HTML注释式结构
不再是必需的,不应该使用。
< blockquote class =post_quotes>
function chgColor(){
^
添加一个形式参数,以便事件可以传递给这个
函数: -
函数chgColor(ev){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag ==" TD"){
document.all(window.event.srcElement.sourceIndex)。 bgColor ="#3280ff";
}
}
因为事件将被传递给函数作为参数没有
需要引用IE的全局事件对象。非IE浏览器使用 -
target - 属性来指示事件的发起者,因此: -
var theTag = ev.srcElement || ev.target;
var theTagName = theTag.tagName;
if(theTagName ==''TD''){
theTag.style .backgroundColor =''#3280ff'';
}
- 但目标可能是TD元素中包含的文本节点,因此它
可能需要链接父节点,直到元素节点遇到
: -
函数chgColor(ev){
var theTagName,theTag = ev.srcElement || ev.target;
while(theTag&& theTag.noteType!= 1){
theTag = theTag.parentNode;
}
if(theTag){
theTagName = theTag.tagName;
if(theTagName ==''TD''){
theTag.style.backgroundColor =''#3280ff'';
}
}
此外,设置元素' - style -
对象的 - backgroundColor - 属性,而不是使用deprecated - bgColor - 属性(除非你
试图积极支持恐龙)比如Netscape 4)。
< snip>
< body onmouseover =" chgColor()"的onmouseout = QUOT; chgBack()"
将事件对象从事件处理传递给您的函数
函数: -
< body onmouseover =" chgColor(event)" onmouseout =" chgBack(event)"
< snip>
Richard Cornford skrev:
< snip>
请不要顶到comp.lang.javascript。
Richard。
Hi!
Here''s a training case at school. The function will animate a table
cell in IE:
function chgColor(){
var thistag, parenttag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
Anybody that can give me the change I need for this to work in Firefox?
Thank you :-)
Krij wrote:Here''s a training case at school. The function will animate
a table cell in IE:
function chgColor(){
var thistag, parenttag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
Anybody that can give me the change I need for this to work in
Firefox?Not without seeing how this function is being called.
Richard.
Sorry, here''s the whole thing:
<html><head><title>JavaScript lessons Work Example</title>
<script language="javascript">
<!--
function chgColor(){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}
function chgBack(){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#c0c0c0";
}
}
//--></script></head>
<body onmouseover="chgColor()" onmouseout="chgBack()" font
face="verdana" size="3" COLOR="#000000">
<center>
<table border="5" bordercolor="#006400" width="30%">
<tr>
<td>MAY</td><td> </td><td> </td><td> </td>
</tr>
<tr>
<td> </td><td>NOT</td><td> </td><td> </td>
</tr>
<tr>
<td> </td><td> </td><td>WORK</td><td> </td>
</tr>
<tr>
<td> </td><td> </td><td> </td><td>IN</td>
</tr>
<tr>
<td>FIREFOX</td><td> </td><td> </td><td> </td>
</tr></table>
Thanks for answering :-)
Richard Cornford skrev:
Krij wrote:Here''s a training case at school. The function will animate
a table cell in IE:
function chgColor(){
var thistag, parenttag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
Anybody that can give me the change I need for this to work in
Firefox?
Not without seeing how this function is being called.
Richard.
Krij wrote:
<snip><script language="javascript">The language attribute is deprecated and the type attribute required in
valid HTML 4, and its use makes the language attribute redundant:-
<script type="text/javascript">
<!--This ''hide from older browsers'' stuff with HTML comment-like structures
is no longer necessary and should not be used.
function chgColor(){^
Add a formal parameter so that the event can be passed to this
function:-
function chgColor(ev){
var thistag;
thistag = window.event.srcElement.tagName;
if(thistag == "TD"){
document.all(window.event.srcElement.sourceIndex). bgColor = "#3280ff";
}
}As the event will be passed to the function as an argument there is no
need to reference IE''s global event object. Non-IE browsers use the -
target - property to indicate the originator of the event, so:-
var theTag = ev.srcElement || ev.target;
var theTagName = theTag.tagName;
if(theTagName == ''TD''){
theTag.style.backgroundColor = ''#3280ff'';
}
- but the target may be a text node contained within an TD element so it
might be necessary to chain up the parent nodes until an element node is
encountered:-
function chgColor(ev){
var theTagName , theTag = ev.srcElement || ev.target;
while(theTag && theTag.noteType != 1){
theTag = theTag.parentNode;
}
if(theTag){
theTagName = theTag.tagName;
if(theTagName == ''TD''){
theTag.style.backgroundColor = ''#3280ff'';
}
}
Also, set the - backgroundColor - property of the element''s - style -
object instead of using the deprecated - bgColor - property (unless you
are trying to actively support dinosaurs like Netscape 4).
<snip><body onmouseover="chgColor()" onmouseout="chgBack()"Pass the event object(s) to your function from the event handing
functions:-
<body onmouseover="chgColor(event)" onmouseout="chgBack(event)"
<snip>Richard Cornford skrev:<snip>
Please do not top-post to comp.lang.javascript.
Richard.
这篇关于Herlp与Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!