百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>html5教程> html中的特别字符怎样源码导出
分享文章到:

html中的特别字符怎样源码导出

发布时间:09/01 来源:未知 浏览: 关键词:

要实现Html中非凡字符不被转义(源码输出),有以下三种办法:办法一:

(引荐教程:html教程)

将HTML代码嵌入到<script type='text/html' style='display:block'></scipt>中

<script type='text/html' style='display:block'> <input type="text" /> </scipt>

举例:

	body>
		<pre>
		<script type="text/html" style="display: block;">
			<div>哈哈哈</div>
			<h4>dfdfd</h4>
		</script>
		</pre>
	</body>

办法二:

有时候想让一些html的标签不被阅读器说明翻译,直接原样的显示出来,这时可以在想要显示的代码的外面加上<xmp></xmp>,这样<xmp>标签里面的内容将纹丝不动的显示出来。

<xmp>
 	<table>
		<tr>
			<th width="140">a</td>
			<th width="140">b</td>
			<th width="140">c</td>
		</tr>
	</table>
</xmp>

办法三:

动态创立html时,有时需要某些内容源码显示,不停止html解析:

1、input和textarea通过js设定value值,不会对非凡字符(&quot;)停止html解析

2、input和textarea直接写在value,会对非凡字符(&quot;)停止html解析

3、input和textarea通过jquery设定value值,不会对非凡字符(&quot;)停止html解析

4、通过js或者jquery创立input和textarea,直接通过字符串拼接value,会对非凡字符(&quot;)停止html解析

5、通过js或者jquery创立input和textarea,通过js或者jquery设定value,不会对非凡字符(&quot;)停止html解析6.通过js或者jquery创立textarea,通过js(innerHTML)或者jquery(html())设定value,会对非凡字符(&quot;)停止html解析7.js或者jquery增加script需要非凡处置,并且type='text/html'代表源码输出,不及停止html解析渲染

举例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<script src="https://cdn.staticfile.org/jquery/1.8.3/jquery.min.js"></script>
<script>
$(function() {
	//1.input和textarea通过js设定value值,不会对非凡字符(&quot;)停止html解析
	document.getElementById("t1").value="&quot;";
	document.getElementById("t2").value="&quot;";
	alert("t1:" + document.getElementById("t1").value);//&quot;
	alert("t2:" + document.getElementById("t2").value);//&quot;
	
	//2.input和textarea直接写在value,会对非凡字符(&quot;)停止html解析
	alert("t3:" + document.getElementById("t3").value);//"
	alert("t4:" + document.getElementById("t4").value);//"
	
	//3.input和textarea通过jquery设定value值,不会对非凡字符(&quot;)停止html解析
	$("#t5").val("&quot;");
	$("#t6").val("&quot;");
	alert("t5:" + $("#t5").val());//&quot;
	alert("t6:" + $("#t6").val());//&quot;
	
	
	var str = "&quot;";
	
	//4.通过js或者jquery创立input和textarea,直接通过字符串拼接value,会对非凡字符(&quot;)停止html解析
	var t9 = 't10<textarea id="t9">' + str + '</textarea><br><br>';
	$("#div1").append(t9);
	alert("t10:" + $("#t10").val());//"
	
	//5.通过js或者jquery创立input和textarea,通过js或者jquery设定value,不会对非凡字符(&quot;)停止html解析
	var t10 = 't10<textarea id="t10"></textarea><br><br>';
	$("#div1").append(t10);
	$("#t10").val(str);
	alert("t10:" + $("#t10").val());//&quot;
	
	//6.通过js或者jquery创立textarea,通过js(innerHTML)或者jquery(html())设定value,会对非凡字符(&quot;)停止html解析
	var t11 = 't11<textarea id="t11"></textarea><br><br>';
	$("#div1").append(t11);
	$("#t11").html(str);
	alert("t11的text:" + $("#t11").text());//"
	alert("t11的val:" + "t11.val()=" + $("#t11").val());//"
	
	//7.js或者jquery增加script需要非凡处置,并且type='text/html'代表源码输出,不及停止html解析渲染 
	$("#div1").append("<script type='text/html' style='display:block'" +">" + "&quot;</" + "script>"); 
	
});
</script>
</head>
<body>
	t1<input type="text" id="t1" value=""/><br><br>
	t2<textarea id="t2"></textarea><br><br>
	
	t3<input type="text" id="t3" value="&quot;"/><br><br>
	t4<textarea id="t4">&quot;</textarea><br><br>
	
	t5<input type="text" id="t5" value=""/><br><br>
	t6<textarea id="t6"></textarea><br><br>
	
	<div id="div1"></div>
</body>
</html>

以上就是html中的非凡字符怎样源码输出的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有151人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板