<输入类型='文本区域' onmousemove=“toscheck()” >>仅适用于 Firefox
由于某种原因,此代码适用于所有 chrome、safari 和 ei,但不适用于 Firefox。
<script type="text/javascript">
function toscheck(){
if(tos.scrollTop+540 > tos.scrollHeight){
alert(tos.scrollTop + " " + tos.scrollHeight);
}
}
</script>
----------
<textarea name="tos" id="tos" readonly="readonly" onmousemove="toscheck()">text</textarea>
在 FF 上不会触发任何内容,但在所有其他浏览器上工作正常。
但是,
工作正常。
我是 javascript 新手,所以任何帮助将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这实际上不应该在任何浏览器中工作。您的 Javascript 代码中缺少右括号:
That should actually not work in any browser. There is a closing bracket missing in your Javascript code:
Live example
除了您缺少的
}
之外,以关闭您的函数看来我在FF工作。另外,在您的函数中,您可以直接转到tos.property。
您需要将
this
传递到mousemove="toscheck(this)"
并进行如下所示的函数设置:或者从函数中获取文本区域,如下所示:
Live example
Other than your missing
}
to close out your function it seems to work in FF for me.Also, in your function you directly go to
tos.property
.You'll either need to pass
this
into themousemove="toscheck(this)"
and have your function setup like this:Or get your textarea from within the function like this:
最好的解决方案,使用 jQuery,它是自动跨浏览器方法,或者参见此页面了解如何使代码交叉- 由于 re:
和中的实现之间的差异,浏览器兼容
Best solution, use jQuery and it's automatically cross-browser method or see this page regarding making that code cross-browser compatible due to differences between implementation in re:
and
您的实际文本框有多大?也许它的渲染尺寸与您预期的不同和/或滚动高度有点不同?可能是字体大小/分辨率/DPI 设置问题。要尝试解决此问题,请添加少量重叠量,这样您实际上就不必滚动到绝对底部(在 IE 中不起作用,例如使用键盘导航和 Ctrl + End 时)。
顺便说一句,我不会在
onmousemove
中检查这一点,因为人们也可能使用键盘按键进行导航。我建议使用onblur
以及onmouseup
和/或onkeyup
。但是,如果在滚动条上释放鼠标按钮,onmouseup
可能不会触发。How big is your actual text box? Maybe it's rendered in a different size than you expect and/or the scrollheight is a little bit different? Maybe it's a font size/resolution/DPI setting issue. To try to solve it, add a small overlapping amount so you actually don't have to scroll to the absolute bottom (won't work in IE for example when using keyboard navigation and Ctrl + End).
On a side note, I wouldn't check this in
onmousemove
as people might use keyboard keys to navigate as well. I'd suggest usingonblur
and maybeonmouseup
and/oronkeyup
.onmouseup
however might not fire if the mouse button is released while being on the scroll bar.