【发布时间】:2012-03-31 19:25:38
【问题描述】:
在我上一个问题的后面,我在 webkit 浏览器 Safari 和 Chrome 中的以下代码遇到了一些问题:-
// Textarea focus out event.
var renderHandler;
$("textarea").live('focusout', function (e) {
var currentNote = this;
renderHandler = setTimeout( function(){ renderNote(currentNote); }, 100);
});
// handle exceptions
$('.textEdit').live('focusin', function (e) {
clearTimeout(renderHandler);
});
function renderNote( note ){
var itemContent = $(note).val();
itemContent = htmlStrip(itemContent);
itemContent = itemContent.replace(/\n/g, "<br/>"); // New lines
//itemContent = itemContent.replace(/\s/g, " "); // Spaces
// Formatting replacements
itemContent = itemContent
.replace(/\[b\]/gi, "<b>")
.replace(/\[\/b\]/gi, "</b>")
.replace(/\[i\]/gi, "<i>")
.replace(/\[\/i\]/gi, "</i>")
.replace(/\[s\]/gi, "<s>")
.replace(/\[\/s\]/gi, "</s>");
$(note).replaceWith("<p class='notes'>"+ itemContent +"</p>");
}
在 firefox 中,renderHandler 上的最新 clearTimeout 阻止了函数“renderNote”被调用,这允许我处理 focusout 事件的异常。然而,在 webkit 浏览器中,无论如何都会调用 renderNote。
我尝试过 return、return false、preventDefault、stopPropagation、break 但没有任何乐趣。有人遇到过这种情况吗?
这是一个链接:http://www.kryptonite-dove.com/sandbox/animate
如果您双击正文,然后单击注释的正文,您可以看到它的运行情况。
【问题讨论】:
-
工作小提琴演示:jsfiddle.net/userdude/TsuZn
-
其实我看到上面的代码是
functionality.js的一部分。试试看:jsfiddle.net/userdude/TsuZn/1 -
相同的差异伙伴,他们都展示了一个工作示例:)
-
是的,但是第一个不能由感兴趣的 SOer 编辑,因为它包含在
.ready()块中。 -
如果有人单击其中一种文本样式(删除线、粗体、斜体),您是否正在尝试阻止渲染?
标签: javascript jquery google-chrome safari webkit