<script runat="server" language="jscript">
function getnewurl(url,json_str){
var typ=1;//1為開啟轉(zhuǎn)換
var addstr="",newurl="",url_name="",str="",json={};
if(typ==1){
if(json_str.indexOf("{")!=-1&&json_str.indexOf("}")!=-1){
json=eval("("+json_str+")");
}else{
var arr=json_str.split("?");
if(json_str.indexOf("?")!=-1){
if(url==""){
url=arr[0];
}
str=arr[1];
}else{
str="";
if(url==""){
url=json_str;
}
}
var arr=str.split("&");
for(var key in arr){
if(arr[key]!=""){
var arr1=arr[key].split("=");
if(arr1.length>1){
json[arr1[0]]=arr1[1];
}else{
json[arr1[0]]="";
}
}
}
}
url_name=url.replace(new RegExp(".asp","g"),"");
for(var key in json){
addstr+="-"+key+"-"+json[key];
}
newurl=url_name+addstr+".html";
}else{
for(var key in json){
if(addstr!=""){
addstr+="&"+key+"="+json[key];
}else{
addstr+=key+"="+json[key];
}
}
if(url.indexOf("?")==-1){
newurl=url+"?"+addstr;
}else{
if(addstr!=""){
newurl=url+"&"+addstr;
}
}
}
return newurl
}
</script>
注runat="server" 是讓js運(yùn)行在服務(wù)器端上 也就成為asp函數(shù)的
調(diào)用一:
<a href=“<%=getnewurl("","product.asp?id=1")%>”>產(chǎn)品</a>
結(jié)果是
<a href=“product-id-1.html”>產(chǎn)品</a>
調(diào)用二:
<a href=“<%=getnewurl("product.asp","{""id"":""2""}")%>”>產(chǎn)品</a>
結(jié)果是
<a href=“product-id-2.html”>產(chǎn)品</a>