问两个javascript函数的用途:
一个是:function preprocessURL(url,conditions) {
if(conditions==null||conditions.length==0) return url;
var beginIndex = 0;
var endIndex = url.indexOf("?",beginIndex);
if(endIndex>0){
var newURL = "";
newURL+=url.substring(beginIndex, endIndex);
newURL+="?";
for(var i=0;i<conditions.length;i++){
var condition = conditions[i];
var conditionValue = condition;
if(/^[&\$]/.test(condition)){
condition = condition.substring(1,condition.length); var conditionObj = document.all(condition);
if(conditionObj == null){
alert("Condition identified by '" + conditions[i] + "' not exist!");
continue;
}
conditionValue = conditionObj.value;
}
beginIndex = endIndex+1;
endIndex = url.indexOf("?",beginIndex);
if(endIndex<0)
break;
newURL += url.substring(beginIndex, endIndex);
newURL +=conditionValue;
}
return newURL;
}else{
return url;
}
};
还有一个:function populateValueToTarget(value,targets,seperatorOrReturnValueProperty){ if(targets==null||value==null)
return; var splitValues = null;
var splitTargets = targets.split(",");
if(value instanceof String || typeof(value)=='string'){ //如果返回值为字符串
if(seperatorOrReturnValueProperty==null||seperatorOrReturnValueProperty=='')
seperatorOrReturnValueProperty=",";
splitValues = splitString(value,seperatorOrReturnValueProperty);
}else{ //如果返回值为js对象 splitValues = new Array(); if(seperatorOrReturnValueProperty==null||seperatorOrReturnValueProperty==''){
for (var aProperty in value){
splitValues[splitValues.length] = value[aProperty];
}
}else{
var properties = seperatorOrReturnValueProperty.split(",");
for(var i=0;i<properties.length;i++){
splitValues[splitValues.length] = value[properties[i]];
}
}
}
if(splitValues==null||splitTargets==null)
return; var length = splitValues.length > splitTargets.length? splitTargets.length:splitValues.length;
for(var i=0;i<length;i++){
if(splitTargets[i] == "#")
continue;
var element = document.all(splitTargets[i]);
if(element==null){
alert("Element identified by " + splitTargets[i] + " not exist!");
}
document.all(splitTargets[i]).value = splitValues[i];
//触发数据变化的处理 }
for(var i=0;i<length;i++){
var htmlElement = document.all(splitTargets[i]);
if(htmlElement.onchange!="undefined"&&htmlElement.onchange!=null)
htmlElement.onchange();
}
}
一个是:function preprocessURL(url,conditions) {
if(conditions==null||conditions.length==0) return url;
var beginIndex = 0;
var endIndex = url.indexOf("?",beginIndex);
if(endIndex>0){
var newURL = "";
newURL+=url.substring(beginIndex, endIndex);
newURL+="?";
for(var i=0;i<conditions.length;i++){
var condition = conditions[i];
var conditionValue = condition;
if(/^[&\$]/.test(condition)){
condition = condition.substring(1,condition.length); var conditionObj = document.all(condition);
if(conditionObj == null){
alert("Condition identified by '" + conditions[i] + "' not exist!");
continue;
}
conditionValue = conditionObj.value;
}
beginIndex = endIndex+1;
endIndex = url.indexOf("?",beginIndex);
if(endIndex<0)
break;
newURL += url.substring(beginIndex, endIndex);
newURL +=conditionValue;
}
return newURL;
}else{
return url;
}
};
还有一个:function populateValueToTarget(value,targets,seperatorOrReturnValueProperty){ if(targets==null||value==null)
return; var splitValues = null;
var splitTargets = targets.split(",");
if(value instanceof String || typeof(value)=='string'){ //如果返回值为字符串
if(seperatorOrReturnValueProperty==null||seperatorOrReturnValueProperty=='')
seperatorOrReturnValueProperty=",";
splitValues = splitString(value,seperatorOrReturnValueProperty);
}else{ //如果返回值为js对象 splitValues = new Array(); if(seperatorOrReturnValueProperty==null||seperatorOrReturnValueProperty==''){
for (var aProperty in value){
splitValues[splitValues.length] = value[aProperty];
}
}else{
var properties = seperatorOrReturnValueProperty.split(",");
for(var i=0;i<properties.length;i++){
splitValues[splitValues.length] = value[properties[i]];
}
}
}
if(splitValues==null||splitTargets==null)
return; var length = splitValues.length > splitTargets.length? splitTargets.length:splitValues.length;
for(var i=0;i<length;i++){
if(splitTargets[i] == "#")
continue;
var element = document.all(splitTargets[i]);
if(element==null){
alert("Element identified by " + splitTargets[i] + " not exist!");
}
document.all(splitTargets[i]).value = splitValues[i];
//触发数据变化的处理 }
for(var i=0;i<length;i++){
var htmlElement = document.all(splitTargets[i]);
if(htmlElement.onchange!="undefined"&&htmlElement.onchange!=null)
htmlElement.onchange();
}
}
解决方案 »
- 用户长时间无操作后,如何保存当前状态并要求重新输入密码
- 求助,实时站内信
- jsp中text的值如何在程序中设定
- HTML 模式对话框
- JDBC Connection pool corrupted WebSphere 连接池
- vect的问题,在线等!
- Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
- 在servlet/jsp中,如何自动定时刷新页面显示状态,急!!!
- 帮忙调试一下这个JSP程序
- 取消easyUI——dataGird的因为鼠标点击而自动滚动的事件
- 急 请高手帮忙在做分页时 DAO类报错
- ajax回传的字符串大小有没有限制?
如果我的conditions里面是{"&a", "$b"}, url是http://www.baidu.com?a=?&b=?,且页面元素有name为a和b两个元素,且值为1和2,那么返回的url是http://www.baidu.com?a=1&b=2所以,第一个方法是用来做参数绑定的,如果以&或者$开头,那么这个condition表示的是元素名,参数用元素值绑定。否则那个就是就代表具体的值,直接绑定进url的对应参数中。
如果, seperatorOrReturnValueProperty是"#",value是"a#b",splitTargets是{"name","no"},那么页面上name为"name","no"的元素的值分别变为"a", "b",并且触发onchange相应的事件。
如果, seperatorOrReturnValueProperty是"a,b",value是具有a和b属性的对象,并且之分别为1和2,splitTargets是{"name","no"},那么页面上name为"name","no"的元素的值分别变为"1", "2",并且触发onchange相应的事件。并且,splitTargets的某一项如果为#,则那一项的页面元素的值不变。如果value为string时,seperatorOrReturnValueProperty的默认值为","。否则,seperatorOrReturnValueProperty的默认值是value的每个属性。