[英]Span not wrapping inside div
I'm trying to highlight textarea words by putting a div
behind my field and copying over the values. 我试图通过在字段后面放置一个
div
并复制值来突出显示textarea单词。
$("div").html($("textarea").text()
.replace("bad-word", "<span style='background-color: red'>bad-word</span>"))
I mocked it up and it works fine in Chrome. 我对其进行了模拟,并在Chrome中正常运行。 But in IE it seems that
span
s won't jump to the next line of the div
, when the word is too big to fit on that row. 但是在IE中,当单词太大而无法插入该行时,
span
似乎不会跳到div
的下一行。 Instead it seems to force a break-word sort of effect - which the textarea
doesn't do, so the words don't align anymore. 取而代之的是,它似乎强制使用了断词效果
textarea
不会这样做,因此单词不再对齐。 Tested in IE8 + 9. 在IE8 + 9中测试。
Screenshot, code result in IE 9
屏幕截图,IE 9中的代码结果
Here's a fiddle . 这是一个小提琴 。 try adding a letter at the start of the textarea and you'll see what I mean.
尝试在文本区域的开头添加一个字母,您会明白我的意思。
$("#g1").val("This is me talking about pizza, cheese and also other pizza too hello! how are you?");
$("#g1").keyup(function(e) {
keyUp(this);
})
function keyUp( el ) {
var txtArea = $(el);
var txtAVal = txtArea .val();
txtAVal = txtAVal.replace(/pizza/gi, "<span style='background:red'>pizza</span>");
$("#g2").html(txtAVal );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.