今天做文本域编辑和提交,文本域的内容最好带格式,于是找了一些插件,最后选择了jHtmlArea
下载地址:[url]http://jhtmlarea.codeplex.com[/url]
[img]http://dl2.iteye.com/upload/attachment/0121/1643/d90bb9bc-a62a-334c-b779-16825ecd8a06.png[/img]
替换字符串中的”为'
去除字符串中的html标签
下载地址:[url]http://jhtmlarea.codeplex.com[/url]
[img]http://dl2.iteye.com/upload/attachment/0121/1643/d90bb9bc-a62a-334c-b779-16825ecd8a06.png[/img]
<!DOCTYPE html >
<html>
<head>
<title></title>
<script type="text/javascript" src="scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="Stylesheet" type="text/css" href="style/jqueryui/ui-lightness/jquery-ui-1.7.2.custom.css" />
<script type="text/javascript" src="scripts/jHtmlArea-0.8.js"></script>
<link rel="Stylesheet" type="text/css" href="style/jHtmlArea.css" />
<script type="text/javascript">
// You can do this to perform a global override of any of the "default" options
// jHtmlArea.fn.defaultOptions.css = "jHtmlArea.Editor.css";
$(function() {
$("#txtDefaultHtmlArea").htmlarea(); // Initialize jHtmlArea's with all default values
});
});
</script>
<textarea id="txtDefaultHtmlArea" cols="50" rows="15"><p><h3>Test H3</h3>This is some sample text to test out the <b>WYSIWYG Control</b>.</p></textarea>
<input type="button" value="Alert HTML" onclick="alert($('#txtDefaultHtmlArea').htmlarea('html'));" />
<input type="button" value="Set HTML" onclick="$('#txtDefaultHtmlArea').htmlarea('html', 'Some <strong>HTML</strong> value.')" />
<input type="button" value="Change Color to Blue" onclick="$('#txtDefaultHtmlArea').htmlarea('forecolor', 'blue');" />
</body>
</html>
替换字符串中的”为'
var name = '"a", "b"';
name.replace(/"([^"]*)"/g, "'$1'");
"'a', 'b'"
去除字符串中的html标签
var a = '<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">asdfffaASDF阿德上风格</blockquote>';
a.replace(/<[^>]+>/g,"");
"asdfffaASDF阿德上风格"
去除所有空格:.replace(/\s+/g,"")
去除左边空格:.replace(/^\s*/,"");
去除右边空格:.replace(/(\s*$)/g,"");
去除两边空格:.replace(/^\s+|\s+$/g,"")