更新时 Javascript 文本呈现错误(仅限 webkit)
我正在尝试点击时切换文本。单击“暂停”时,将文本更改为“播放”。
由于某种原因,文本正在更新,但无法正确呈现。就好像 DOM 的那部分正在更新但没有刷新。由于某种原因,这只发生在 webkit 浏览器(Safari 5、Chrome 11)中。 Firefox 4 正在以应有的方式呈现它。
以下是有关该问题的视频:http://www.youtube.com/watch?v=tIRKx25NmYo< /a>
我在视频中使用 Cmd+A 选择文本,这似乎刷新了文本并使其正确显示。
这是代码:
<span class="playercontrols" id="playpause" onclick="toggle(this.id);" style="cursor:pointer;">Pause</span>
<script type="text/javascript">
function toggle(sender){
var t = document.getElementById(sender);
var txt = t.innerHTML;
switch(txt)
{
case 'Pause':
txt = 'Play';
pause();
break;
case 'Play':
txt = 'Pause';
play();
break;
default:
txt = 'Pause';
}
t.innerHTML = txt;
}
</script>
编辑:我注释掉了页面上引用和编写的所有其他 javascript 片段,问题仍然存在。我不知道出了什么问题,但看起来并不是碰撞或冲突。
解决了。 (不允许标记此答案,因为它太新了。)
编辑:答案现在添加在下面。
感谢所有的评论。希望这篇文章能够帮助其他遇到同样问题的人。
I'm trying to toggle text on click. When 'Pause' is clicked change the text to 'Play'.
For some reason the text is updating but not rendering correctly. It's as if that part of the DOM is being updated but not refreshed. For some reason this is only happening in the webkit browsers (Safari 5, Chrome 11). Firefox 4 is rendering it the way it should.
Here's a video of the problem: http://www.youtube.com/watch?v=tIRKx25NmYo
I'm using Cmd+A in the video to select the text, which appears to refresh the text and get it to display properly.
Here's the code:
<span class="playercontrols" id="playpause" onclick="toggle(this.id);" style="cursor:pointer;">Pause</span>
<script type="text/javascript">
function toggle(sender){
var t = document.getElementById(sender);
var txt = t.innerHTML;
switch(txt)
{
case 'Pause':
txt = 'Play';
pause();
break;
case 'Play':
txt = 'Pause';
play();
break;
default:
txt = 'Pause';
}
t.innerHTML = txt;
}
</script>
EDIT: I commented out every other piece of javascript referenced and written on the page and the problem is still there. I have no idea what's wrong but it doesn't appear to be a collision or conflict.
SOLVED IT. (Not allowed to mark this answered because it's too recent.)
Edit: Answer now added below.
Thanks for all the comments. Hopefully this post will help others in the future with the same problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎闪烁文本(将
可见性
设置为隐藏
,然后返回其原始值)可以解决问题。所以这是工作大约。
演示 http://jsfiddle.net/gaby/SgwsZ/4/
It seems that flashing the text (setting
visibility
tohidden
and then back to its original value) fixes the issue..So here is the work around.
demo http://jsfiddle.net/gaby/SgwsZ/4/
问题出在“playercontrols”类的样式上。
我将它设置为相对位置,这显然使 webkit 的更新渲染变得不正常。
The problem was with the styling on the "playercontrols" class.
I had it set to position relative which apparently sent webkit's update rendering out of whack.