暂时隐藏HTML代码并稍后显示 [英] Hide HTML code temporarily and display them later

查看:155
本文介绍了暂时隐藏HTML代码并稍后显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从textarea-tag(TEMPORARILY)中删除所有的HTML标签,然后在页面上显示textarea的值。

 < textarea>< span style =color:blue>测试< / p>< / textarea>< br /> 

在这里显示textarea:< span id =show>< / span>

我的jQuery

  $( #节目)的HTML($( 文本域)VAL()。)。 

http://jsfiddle.net/vQD5w/



这就是我现在显示textarea内容的方式,这就是它的方式最后看。同时我想隐藏textarea中的HTML代码,所以textarea里面的内容对普通的PC用户来说并不难看,也不可读。因此,Textarea应该只包含Test(不含引号)。

因此基本上我想要转义所有HTML标记,元素和与HTML相关的所有内容textarea-tag ,但稍后使用它。

解决方案

您可以使用正则表达式去除标签barring,你不是试图解析它。$ / b
$ b

  $(#show)。html($(textarea)。val()); 
var text = $('textarea')。val();
$('textarea').val(text.replace(/(<([^> +)>)/ ig,));

示例: http://jsfiddle.net/brandonscript/ffC4q/


I am trying to remove all HTML tags from a textarea-tag (TEMPORARILY), but then display the textarea value after that on the page.

<textarea><span style="color: blue">Test</p></textarea><br />

Show textarea here: <span id="show"></span>

My jQuery

$("#show").html($("textarea").val());

http://jsfiddle.net/vQD5w/

That is how I show the textarea content at the moment, and that is how it is going to look in the end. Meanwhile I want to hide the HTML code from the textarea, so what is inside the textarea does not look ugly and unreadable to the common PC user. Textarea should therefore only contain "Test" (no quotations).

So basically I want to escape all HTML tags, elements, and everything related to HTML INSIDE the textarea-tag, but use it later on.

解决方案

You could use regular expressions to strip out the tags, barring that you aren't trying to parse it.

$("#show").html($("textarea").val());
var text = $('textarea').val();
$('textarea').val(text.replace(/(<([^>]+)>)/ig,""));

Example: http://jsfiddle.net/brandonscript/ffC4q/

这篇关于暂时隐藏HTML代码并稍后显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆