viewer.js

来自「关于网上汽车销售系统的详细编程项目实战实例」· JavaScript 代码 · 共 80 行

JS
80
字号
/**
 * viewer.js
 *
 * @author  Actuate Corporation
 * @version 1.0
 */

function replaceDuplicateParams(sURL, sRegExp, sValue)
{
	var pattern = sRegExp + "=\[A-Za-z0-9_%]*&?";
	var regExp = new RegExp( pattern, "i");
	//alert("replaceDuplicateParams sURL= "+sURL+" regExp= "+regExp); 
	var resultArray = regExp.exec(sURL);
	var listArray = sURL.split(regExp);
	var sRetURL = null;
	
	// Check if the parameter is already existing in the url
	if( resultArray != null)
	{
		//Check if more than one occurances are found in the url for the given parameter
		if( resultArray.length == 1)
		{
			// Replace the value of the parameter with the new value
			
			if( listArray.length == 1 || listArray[1] == "")
			{
				//sRetURL = listArray[0] + sRegExp + sValue;
				sRetURL = sURL.replace(regExp, sRegExp +"="+ sValue);
			}
			else
			{
				sRetURL = sURL.replace(regExp, sRegExp + "="+ sValue + "&");
				
			}
			
			// End of replace the value of the parameter with the new value
		}
		else
		{
		}
	}
	else
	{
		sRetURL = sURL + "&" + sRegExp + "="+ sValue;
	}
	return sRetURL;
}

/**
 *
 */
function removeParams(sObjURL, sParam)
{
	var pattern = sParam + "=[^&]*&?";
	var regExp = new RegExp( pattern, "i");
	var resultArray = regExp.exec(sObjURL);
	var listArray = sObjURL.split(regExp);
	var sRetURL = null;

	// Check if the parameter is existing in the url
	if( resultArray != null)
	{
		// Remove the  the parameter 
			if( listArray.length == 1 || listArray[1] == "")
			{
				sRetURL = sObjURL.substring(0 , (listArray[0].length-1));
			}
			else
			{
				sRetURL = sObjURL.replace(regExp, "");
			}
	}
	else
	{
			sRetURL = sObjURL;
	}
	return sRetURL;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?