Home > Article > Web Front-end > Detailed explanation of js rich text processing and form submission function examples
本文主要和大家分享js富文本处理和表单提交功能实例详解,主要以代码的形式和大家分享,希望能帮助到大家。
一,js处理富文本
function decodeHtml(s) { var HTML_DECODE = { "<": "<", ">": ">", "&": "&", " ": " ", """: "\"", "©": "" // Add more }; var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g; var REGX_HTML_DECODE = /&\w+;|&#(\d+);/g; var REGX_TRIM = /(^\s*)|(\s*$)/g; s = (s != undefined) ? s : ""; return (typeof s != "string") ? s : s.replace(REGX_HTML_DECODE, function ($0, $1) { var c = HTML_DECODE[$0]; if (c == undefined) { // Maybe is Entity Number if (!isNaN($1)) { c = String.fromCharCode(($1 == 160) ? 32 : $1); } else { c = $0; } } return c; }); }; $(document).ready(function(){ var content= "{{$data['content']}}"; $("#content").append(decodeHtml(content)); });
二,表单提交
//获取表单的所有数据 var form_data = $('#From_id_2').serializeArray(); var m = [], idata; $.each(form_data, function (i, field) { m.push('"' + field.name + '":"' + encodeURI(field.value) + '"'); }); idata = '{' + m.join(',') + '}'; // 按字符 idata 转换成 JSON 格式 idata = eval('(' + idata + ')'); console.log(idata); //表单的所有数据,可以直接提交到后台
相关推荐:
The above is the detailed content of Detailed explanation of js rich text processing and form submission function examples. For more information, please follow other related articles on the PHP Chinese website!