English 中文(简体)
将选定的超文本放在j Query
原标题:Replacing selected HTML text in jQuery

我有这部法律取代某些案文:(在选定案文之前和之后加上“1”和“2”):

var content=$("#text").html();
if (window.getSelection) {
 // not IE case
 var selObj = window.getSelection(); 
 var selRange = selObj.getRangeAt(0);

 content2 = content.substring(0,selRange.startOffset) + "1" + content.substring(selRange.startOffset,selRange.endOffset) + "2" + content.substring(selRange.endOffset,content.length);
 $("#content").html(content2);
 selRange.removeAllRanges();
} else if (document.selection && document.selection.createRange && document.selection.type != "None") {
 // IE case
 range = document.selection.createRange();
 var selectedText = range.text; 
 var newText =  1  + selectedText +  2 ; 
 document.selection.createRange().text = newText; 
}

和超文本:

<div id="text">aaa as asd das d</div>

这与“纯”文本良好,但如果我的超文本看着这种(原案文)一样。

<div id="text">aaa as <b>asd</b> das d</div>

它在火fox中被击落,因为塞尔日。 开始 标 标 标 题

另一问题...... 在独立实体中,该校正用黑体字和“热”文本进行罚款,但由于IEm不使用jquery html()功能,案文只能用超文本取代。 因此,如果我想要使用“并”、“b>”;和“</b>”而不是“1”和“2”,则案文不会像在火法中那样大胆。

能否确定这两个问题?

最佳回答
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!