日期:2014-05-16 浏览次数:20540 次
<html> <body> <a href="javascript:addUrl('key1')">连接1,哈哈,你点击这里你的URL就变长了点点,试试看</a><br/> <a href="javascript:addUrl('key2')">连接2,哈哈,你点击这里你的URL又会变长了点点,不信你就试试看</a><br/> <a href="javascript:addUrl('key3')">连接3,哈哈,你点击这里你的URL会变更长了,不信我就自杀</a><br/> <a href="test.php" id="link4" target="_blank">连接4(就是你要来回变那个玩意)</a> </body> <script language="javascript"> function tempObj(pori,keyinfo) { this.pori = pori; //前缀表达式 this.keyinfo = keyinfo;//值信息存储 this.isUsed = "0";//该对象是否已经使用,若使用变成1,初始化为0 this.getPori = function() { return this.pori; } this.getKeyinfo = function() { return this.keyinfo; } this.getIsUsed = function() { return this.isUsed; } this.setIsUsed = function(isUsed) { this.isUsed = isUsed; } } var addInfo = { "key1":new tempObj("link=","1"), "key2":new tempObj("link=","2"), "key3":new tempObj("mode=","3") }; var nowInfo = {"beginUrl":"test.php"}; var nowSize = 1; function addUrl(key) { var obj = addInfo[key]; if(obj.getIsUsed() == "1") { alert("这个连接啦,URL不会因为你这个连接变化啦,已经增加过了,不要在点啦,在点就报警啦,哈哈。。。"); return; } obj.setIsUsed("1");//设置该节点已经被使用 if(nowSize == 1) { nowInfo[obj.getPori()] = "?"+obj.getPori()+obj.getKeyinfo(); getUrlObj().href = getUrlObj().href + nowInfo[obj.getPori()]; }else { var needUri = nowInfo[obj.getPori()]; if(needUri == undefined) {//没有找到相同前缀的URL nowInfo[obj.getPori()] = "&" + obj.getPori()+obj.getKeyinfo(); getUrlObj().href = getUrlObj().href + nowInfo[obj.getPori()]; }else { getUrlObj().href = getUrlObj().href.replace(needUri,needUri+","+obj.getKeyinfo()); nowInfo[obj.getPori()] = needUri+","+obj.getKeyinfo(); } } nowSize ++; showUrl(); } function getUrlObj() { return document.g