序列化中文時之所以亂碼是因為.serialize()調用了encodeURLComponent方法將數據編碼了
解決方法就是進行解碼
原因:.serialize()自動調用了encodeURIComponent方法將數據編碼了
解決方法:調用decodeURIComponent(XXX,true);將數據解碼
//商品標簽
function tag(url){
var form = $('form').serialize(); //序列化內容
var shuju = decodeURIComponent(form,true); //將數據解碼
alert(shuju);
return false;
if(url.indexOf("?") >= 0){
var newurl = url + $('form').serialize();
window.location.href = newurl;
}else{
var form = $('form').serialize();
var shuju = decodeURIComponent(form,true);
alert(shuju);
var newurl = url + '?' + shuju;
window.location.href = newurl;
}
}
//解決辦法:將解碼方式unscape換為decodeURI
//原因:瀏覽器會將url中的中文參數進行encodeURI編碼,所以要通過js使用decodeURI進行解碼
var url = decodeURI(location.href); //decodeURI() 函數可對 encodeURI() 函數編碼過的 URI 進行解碼。
//jq獲取百度編輯器的內容
var test = editor.getContent();
