本文介绍了Herlp与Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨! 这是'在学校的培训案例。该函数将在IE中为表格设置动画: 函数chgColor(){ var thistag,parenttag; thistag = window.event.srcElement.tagName; if(thistag ==" TD"){ document.all(window.event .srcElement.sourceIndex)。 bgColor ="#3280ff"; 有谁可以给我这个在Firefox上工作所需的改变吗? 谢谢:-) 解决方案 并非没有看到如何调用此函数。 Richard。 并非没有看到如何调用此函数。 Richard。 不推荐使用language属性,并且 有效HTML 4中需要type属性,并且使用它会使语言属性变得多余: - < script type =" text / javascript"> 这种隐藏旧浏览器的HTML注释式结构 不再是必需的,不应该使用。 function chgColor(){ ^ 添加一个形式参数,以便事件可以传递给这个 函数: - 函数chgColor(ev){ 因为事件将被传递给函数作为参数没有 需要引用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(event)" onmouseout =" chgBack(event)" < snip> < snip> 请不要顶到comp.lang.javascript。 Richard。 Hi! Here''s a training case at school. The function will animate a tablecell 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 :-) 解决方案 Not without seeing how this function is being called. Richard. Not without seeing how this function is being called.Richard.The language attribute is deprecated and the type attribute required invalid HTML 4, and its use makes the language attribute redundant:- <script type="text/javascript"> This ''hide from older browsers'' stuff with HTML comment-like structuresis no longer necessary and should not be used. ^Add a formal parameter so that the event can be passed to thisfunction:- function chgColor(ev){ As the event will be passed to the function as an argument there is noneed 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 itmight be necessary to chain up the parent nodes until an element node isencountered:- 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 youare trying to actively support dinosaurs like Netscape 4). <snip>Pass the event object(s) to your function from the event handingfunctions:- <body onmouseover="chgColor(event)" onmouseout="chgBack(event)" <snip><snip> Please do not top-post to comp.lang.javascript. Richard. 这篇关于Herlp与Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 22:26