<html>
<head>
<title>测试编码</title>
<script>
function doEncode(){
var con = document.getElementById("content");
con.value = encodeURIComponent(con);
alert(con.value);
}
function doDecode(){
var con = document.getElementById("content");
con.value = decodeURIComponent(con);
alert(con.value[0]);
}
function newGuid()
{
var guid = "";
for (var i = 1; i <= 32; i++){
var n = Math.floor(Math.random()*16.0).toString(16);
guid +=n;
}
alert(guid.toUpperCase());
guid += new Date().getTime();
alert(guid.toUpperCase());
return guid.toUpperCase();
}
function toNewGuid(){
alert(newGuid());
}
</script>
</head>
<body>
<input type="text" id="content"/><br/>
<input type="button" onclick="doEncode()" value="Encode"/>
<input type="button" onclick="doDecode()" value="Decode"/>
<input type="button" onclick="toNewGuid()" value="GUID"/>
</body>
</html>
本文介绍了一个简单的HTML页面示例,该示例演示了如何使用JavaScript进行URL编码(encodeURIComponent)与解码(decodeURIComponent),同时展示了如何生成一个全局唯一标识符(GUID)。通过两个按钮操作,用户可以直观地看到文本输入框中内容的变化。

被折叠的 条评论
为什么被折叠?



