本文實(shí)例講述了JavaScript使用encodeURI()和decodeURI()獲取字符串值的方法。分享給大家供大家參考。具體如下:
JavaScript使用encodeURI()和decodeURI()獲取字符串值,不能就是地址欄顯示的字串,以前經(jīng)常在網(wǎng)上見到有人問此問題,無意在網(wǎng)上發(fā)現(xiàn),不知是不是您想要的,先看看效果吧。
先來看看運(yùn)行效果:

具體代碼如下:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>使用系統(tǒng)函數(shù)</title><script language="JavaScript"><!-- function showMsg() { var strURL= url.value; var encodeStr = encodeURI(strURL); var temp = encodeStr+"/n"; temp += decodeURI(encodeStr); alert(temp); }--></script> </head><body><div> 請輸入一個URL:<input name="url" type="text" id="url" value="/search.php?keyword=搜索關(guān)鍵字" size="60" /> <input type="submit" name="button" id="button" value="我要提交" onclick="showMsg();" /></div> <dIV class="vc" style="margin: 20px auto" ><h2>使用encodeURI()和decodeURI()函數(shù):</h2></dIV></body></html>希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答