IE / Chrome中未定义的功能,但Firefox中没有(Undefined functions in IE/Chrome but not in Firefox)

编程入门 行业动态 更新时间:2024-10-26 17:19:18
IE / Chrome中未定义的功能,但Firefox中没有(Undefined functions in IE/Chrome but not in Firefox)

所以我有这个代码,这是一个php文件的输出(因此有些东西比如3个评级等)。

它在Firefox中完美运行,但Chrome和IE就像观察者甚至不存在一样。

此外,#ratingwrapper的onmouseout函数在chrome和ie中被视为“未定义”。 令人难以置信的是为什么这两个浏览器完全忽略了JS,但firefox看到了一切。

我尝试了所有的东西,甚至调用简单的警报,没有任何工作在ie和chrome。 我尝试删除观察者并在#ratingwrapper div中执行所有操作,但所有函数都在chrome中“未定义”。

我正在使用原型,头js声明都是有序的,因为使用原型的其他脚本正在页面上工作。 没有冲突等等我坚持这个无法解释的错误。

<div class="ratings"> <div class="rating-box" id="ratingbox"> <div class="rating" id="ratingboxfill" style="width:100%"></div> </div> <div id="ratingwrapper" onmouseout="revertProductRating()"></div> <br /><br /> <div id="curpos"></div> <div id="cpos"></div> <span class="amount">3 ratings</span> <input id="newRating" type="hidden" value="0" /> </div> <script type="text/javascript"> function setNewProductRating(e) { var ratingx = Event.pointerX(e); var ratingy = Event.pointerY(e); var containerLeft = Position.page($('ratingbox'))[0]; var containerTop = Position.page($('ratingbox'))[1]; var hpos = ratingx - containerLeft; var vpos = ratingy - containerTop; $("cpos").update(hpos+","+vpos); if (hpos <= 9) { revertProductRating(10) $("newRating").value=1; } else if(hpos <19) { revertProductRating(20) $("newRating").value=2; } else if(hpos <28) { revertProductRating(30) $("newRating").value=3; } else if(hpos <38) { revertProductRating(40) $("newRating").value=4; } else if (hpos < 47) { revertProductRating(50) $("newRating").value=5; } else if (hpos < 57) { revertProductRating(60) $("newRating").value=6; } else if (hpos < 66) { revertProductRating(70) $("newRating").value=7; } else if (hpos < 76) { revertProductRating(80) $("newRating").value=8; } else if (hpos < 85) { revertProductRating(90) $("newRating").value=9; } else if (hpos < 96) { revertProductRating(100) $("newRating").value=10; } else { revertProductRating() } } function revertProductRating(force=0) { if (force == 0) { //document.getElementById("ratingboxfill").style.width = "100%"; $("curpos").update("force=0"); $("ratingboxfill").setStyle({ width: '100%' }); } else { //document.getElementById("ratingboxfill").style.width = force+"%"; $("curpos").update("force="+force); $("ratingboxfill").setStyle({ width: force+'%' }); } } function sendProductRating() { value = $("newRating").getValue(); window.location = 'http://x.dev/y/' + 'ratingValue/' + value; } $('ratingwrapper').observe('mousemove', setNewProductRating); $('ratingwrapper').observe('click', sendProductRating); </script>

So I have this code, which is the output of a php file (hence some stuff like 3 ratings, etc).

It works flawlessly in Firefox, but Chrome and IE act like the observers don't even exist.

Also, the onmouseout function of #ratingwrapper is considered "not defined" in chrome and ie. It's mind boggling why these two browsers are totally ignoring the JS, yet firefox sees everything.

I tried absolutely everything, even calling simple alerts, nothing works in ie and chrome. I tried removing the observers and doing everything in the #ratingwrapper div, but all functions are being "undefined" in chrome.

I'm using prototype, header js declarations are all in order, because other scripts using prototype are working on the page. There are no conflicts, etc. I'm stuck with this unexplainable bug.

<div class="ratings"> <div class="rating-box" id="ratingbox"> <div class="rating" id="ratingboxfill" style="width:100%"></div> </div> <div id="ratingwrapper" onmouseout="revertProductRating()"></div> <br /><br /> <div id="curpos"></div> <div id="cpos"></div> <span class="amount">3 ratings</span> <input id="newRating" type="hidden" value="0" /> </div> <script type="text/javascript"> function setNewProductRating(e) { var ratingx = Event.pointerX(e); var ratingy = Event.pointerY(e); var containerLeft = Position.page($('ratingbox'))[0]; var containerTop = Position.page($('ratingbox'))[1]; var hpos = ratingx - containerLeft; var vpos = ratingy - containerTop; $("cpos").update(hpos+","+vpos); if (hpos <= 9) { revertProductRating(10) $("newRating").value=1; } else if(hpos <19) { revertProductRating(20) $("newRating").value=2; } else if(hpos <28) { revertProductRating(30) $("newRating").value=3; } else if(hpos <38) { revertProductRating(40) $("newRating").value=4; } else if (hpos < 47) { revertProductRating(50) $("newRating").value=5; } else if (hpos < 57) { revertProductRating(60) $("newRating").value=6; } else if (hpos < 66) { revertProductRating(70) $("newRating").value=7; } else if (hpos < 76) { revertProductRating(80) $("newRating").value=8; } else if (hpos < 85) { revertProductRating(90) $("newRating").value=9; } else if (hpos < 96) { revertProductRating(100) $("newRating").value=10; } else { revertProductRating() } } function revertProductRating(force=0) { if (force == 0) { //document.getElementById("ratingboxfill").style.width = "100%"; $("curpos").update("force=0"); $("ratingboxfill").setStyle({ width: '100%' }); } else { //document.getElementById("ratingboxfill").style.width = force+"%"; $("curpos").update("force="+force); $("ratingboxfill").setStyle({ width: force+'%' }); } } function sendProductRating() { value = $("newRating").getValue(); window.location = 'http://x.dev/y/' + 'ratingValue/' + value; } $('ratingwrapper').observe('mousemove', setNewProductRating); $('ratingwrapper').observe('click', sendProductRating); </script>

最满意答案

您无法在javascript中定义默认参数值,因此revertProductRating的函数定义是错误的。

尝试将其更改为:

function revertProductRating(force) { if(arguments.length === 0) { force = 0; } if (force == 0) { //document.getElementById("ratingboxfill").style.width = "100%"; $("curpos").update("force=0"); $("ratingboxfill").setStyle({ width: '100%' }); } else { //document.getElementById("ratingboxfill").style.width = force+"%"; $("curpos").update("force="+force); $("ratingboxfill").setStyle({ width: force+'%' }); } }

You can't define default argument values in javascript, so the function definition of revertProductRating is wrong.

Try changing it to this:

function revertProductRating(force) { if(arguments.length === 0) { force = 0; } if (force == 0) { //document.getElementById("ratingboxfill").style.width = "100%"; $("curpos").update("force=0"); $("ratingboxfill").setStyle({ width: '100%' }); } else { //document.getElementById("ratingboxfill").style.width = force+"%"; $("curpos").update("force="+force); $("ratingboxfill").setStyle({ width: force+'%' }); } }

更多推荐

本文发布于:2023-08-02 19:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1380713.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中未   定义   功能   Chrome   Undefined

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!