js实现C#的Server.Encode和Server.Decode
js实现C#的Server.Encode和Server.Decode
C#中Server.URLEncode和Server.URLDecode是对URL进行编码和解码的方法。 今天,在项目中使用了用户控件,可是由于浏览器认为页面中有js错误,于是按钮的搜索事件无法触发。 于是,想到了使用js。 由于搜索内容可能为中文,而URL中有中文有可能会乱码,得对URL进行编码和解码: 在sResult.aspx页面,可以用: 即,URLEncode就和EncodeURI有同样的功能 URIDecode和DecodeURI有同样的功能$(function(){
$("#imgSearch").click(function(){
window.location.href="sResult.aspx?keys="+EncodeURI($("#txtSearch").val());
}):
});
string text="";
try{
text=Request.QueryString["keys"].ToString().Trim();
}
catch(Exception ex)
{
text="":
}