English 中文(简体)
我如何迫使浏览器使标签成为标签,而不是在经过改动的零件上向用户披露:内装机超?
原标题:How do I force the browser to render the tags rather than reveal them to the user on altered div:innerHTML?

I m允许用户选择载于<代码><div></div>的案文并将其改为黑体字。 换言之,从<代码><div> ;该文本是某些文本的复制件;/div> to <div>this is <b>some</b> text</div>。 除此以外,所有方面都在发挥作用,但当我把div.inner/2006/2改为、b>、some<、/b>text<、b>、b>、标签被显示给用户,而不是作为“超”和显示大胆。 这一切都发生在客户的 Java印中。

我如何迫使浏览器向用户提供标签,而不是向用户披露这些标签?

每项要求,此处为法典......

页: 1

<div id="blob">
One simple, but not very efficient implementation of a dictionary is a linked 
list. In this implementation all operations take linear time in the worst case 
(and even in the average case), assuming that insertions first check whether the 
item is in the current list. A more scalable implementation of a dictionary is a 
balanced search tree. In this lecture note we present two even more efficient data 
structures based on hashing.
</div>

Javascript...

tagText(document.getElementById("blob"),"<b>","</b>");

......

//======================================================================
function tagText(el,tagstart,tagend)
    {
    var range = window.getSelection().getRangeAt(0);
    var rtxt = range.startContainer.textContent;
    var rlen = rtxt.length;
    var start = range.startOffset;
    var stop = range.endOffset;
    var result = rtxt.substring(0,start) + tagstart + rtxt.substring(start,stop) + tagend + rtxt.substring(stop,rlen);
//  el.innerHTML = result;
    range.startContainer.textContent = result;
    var txt = el.innerHTML;
    el.innerHTML = txt;
    }
//======================================================================

看一看四点:通过火力推来的内温超显示,标签越出&lt;b&gt; 而不是<b>

最佳回答

That s not what s causing your problem, but.. Isn t this wrong?

var txt = el.innerHTML;
el.innerHTML = txt;

Edit:

为此:

<div id="blob">
One simple, but not very efficient implementation of a dictionary is a linked 
list. In this implementation all operations take linear time in the worst case 
(and even in the average case), assuming that insertions first check whether the 
item is in the current list. A more scalable implementation of a dictionary is a 
balanced search tree. In this lecture note we present two even more efficient data 
structures based on hashing.
</div>

<input type="button" value="sample" onclick= tagText(); >

and...

<script>
  function tagText() {
    var range = window.getSelection().getRangeAt(0);
    range.surroundContents(document.createElement("b"));
  }
</script>
问题回答

我认为,问题是:

range.startContainer.textContent = result;

您实际上没有确定散射元素的内部超文本,你正在确定范围集装箱的正文,该集装箱不会将标记解释为超文本。 相反,试图从你的成果中直接确定微粒的内层超值,并明确范围。

声明——本法典实际上将部分内容合为一。

var rtxt = range.startContainer.textContent;
var rlen = rtxt.length;
var start = range.startOffset;
var stop = range.endOffset;
var result = rtxt.substring(0,start) + tagstart + rtxt.substring(start,stop) + tagend + rtxt.substring(stop,rlen);
el.innerHTML = result;

如果你想要保持甄选,那么你将需要从方案上重新确定范围。

在j Query, d be $ ( #blob ).wrap( <b></b> );。 那么,你甚至不需要写一份助手的职能。 认真使用图书馆。 不要浪费你的时间,把低水平的 st子 out起来。





相关问题
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!