Enjoy Life

A Ryan Gene Blog!

Saturday, August 12, 2006

[Code]JavaScript Selector


刚做完一个小demo,用js模拟了一个selector的东东,想法是这样的:

假页面里的值先填好
如果没有某个参数(fillData),则将form里的值清空,如果带参数,则不要执行清空
打开一个子页面,点击子页面中的某个链接或按钮执行window.opener.location.href =
window.opener.location.href +'?fillData=true';window.close();
父页面(也就是先前说的假页面)就会刷一下,数据出现了


<script language="javascript">
function clearForm(){
for (i=0; i<document.Form1.elements.length; i++){
if (document.Form1.elements[i].type=="text" || document.Form1.elements[i].type=="textarea"){
document.Form1.elements[i].value="";
}
}
}

function checkPara(){
var urlstr = window.document.URL;
var parameterString = urlstr.replace(/.*\?(.*)/, "$1");
var parameterTokens = parameterString.split("&");
var parameterList = new Array();

for (i = 0; i < parameterTokens.length; i++)
{
var parameterName = parameterTokens[i].replace(/(.*)=.*/, "$1");
var parameterValue = parameterTokens[i].replace(/.*=(.*)/, "$1");

parameterList[parameterName] = parameterValue;
}

if( !parameterList["fillData"] )
clearForm();

}
checkPara();
</script>



后续:真实的实现见:
用JavaScript执行PostBack

posted by Ryan Gene at 12:36 AM

0 Comments:

Post a Comment

<< Home

Name:
Location: Shanghai, Shanghai, China

Powered by Blogger
Powered by Writely

Add to Google

Site Feed