您的位置:首页 > Web前端 > HTML

HTML静态页面获取传参的值

2011-03-31 16:33 197 查看
function GetArgsFromHref(sHref, sArgName)
{
var args = sHref.split("?");

if(args[0] == sHref) /*参数为空*/
{
return retval; /*无需做任何处理*/
}
var str = args[1];
args = str.split("&");
for(var i = 0; i < args.length; i ++)
{
str = args[i];
var arg = str.split("=");
if(arg.length <= 1)
continue;
if(arg[0] == sArgName)
retval = arg[1];
}
}


 

具体实例:

在做系统原型(html页面组成)的时候,在 main iframe 中有一个上报数据类型的选择下拉框,下拉框中有两个值,即:季报和年报(默认季报)。当用户选择季报时,左侧 left iframe 菜单中显示的是季报菜单;当用户选择年报时,左侧 left iframe 菜单中显示的是年报菜单。不管选择哪个,右侧除了下拉框的选项有变化外,其他始终不变化,除非点击左侧的某个菜单选项。

 

涉及页面:dl.html (main iframe框架即数据上报选择页面) 和 left2.htm (left iframe框架即菜单页面)

 

main iframe:数据上报类型下拉框bb和一个确定按钮

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录</title>
<link href="../css/css.css" mce_href="css/css.css" rel="stylesheet" type="text/css" />
<link href="../css/css1.css" mce_href="css/css1.css" rel="stylesheet" type="text/css" />
<link href="../css/gy.css" mce_href="css/gy.css" rel="stylesheet" type="text/css" />

<mce:script type="text/javascript"><!--
function openW()
{
var items=document.getElementById("bb");

if(items[0].selected)
{
top.left.window.location.href="left2.htm?flag='"+items[0].value+"'";
}
else
{
top.left.window.location.href="left2.htm?flag='"+items[1].value+"'";
}
}

var retval="";
function GetArgsFromHref(sHref, sArgName) { var args = sHref.split("?"); if(args[0] == sHref) /*参数为空*/ { return retval; /*无需做任何处理*/ } var str = args[1]; args = str.split("&"); for(var i = 0; i < args.length; i ++) { str = args[i]; var arg = str.split("="); if(arg.length <= 1) continue; if(arg[0] == sArgName) retval = arg[1]; } }GetArgsFromHref(window.location.href, "flags");

// --></mce:script>

</head>
<body>
<div class="tu_16">
<div class="shurk">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left">
<select name="select" id="bb">
<option value="jb">季报</option>
<option value="nb">年报</option>
</select>
</td>
</tr>
</table>
</div>
<a href="#" mce_href="#" hidefocus="true" onclick="openW();">
<img src="../images1/icok.gif" mce_src="images1/icok.gif" width="95" height="34" /></a>
</div>

<mce:script type="text/javascript"><!--
if(retval=="'jb'"||retval=="''")
{
document.getElementById("bb").options[0].selected=true;
}
else
{
document.getElementById("bb").options[1].selected=true;
}

// --></mce:script>

</body>
</html>



 

left iframe:菜单(主要关注 KB2Child 和 KB21Child 这部分是根据用户选择数据类型而变化的部分)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>

<mce:script language="JavaScript1.2"><!--
scores = new Array(20);
var numTotal=0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

if (ver4) {
with (document) {
write("<STYLE TYPE='text/css'>");
if (NS4) {
write(".parent {position:absolute; visibility:visible}");
write(".child {position:absolute; visibility:visible}");
write(".regular {position:absolute; visibility:visible}")
}
else {
write(".child {display:none}")
}
write("</STYLE>");
}
}

function getIndex(el) {
ind = null;
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id == el) {
ind = i;
break;
}
}
return ind;
}

function arrange() {
nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
for (i=firstInd+1; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.visibility != "hide") {
whichEl.pageY = nextY;
nextY += whichEl.document.height;
}
}
}

function initIt(){
if (!ver4) return;
if (NS4) {
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
}
arrange();
}
else {
divColl = document.all.tags("DIV");
for (i=0; i<divColl.length; i++) {
whichEl = divColl(i);
if (whichEl.className == "child") whichEl.style.display = "none";
}
}

expandIt('KB1');
//document.all.KB1Child.style.display="block"
}
function expandIt(el) {

if (!ver4) return;
if (IE4) {
if(el=="KB1")
top.main.window.location="../iframe2/dl.html?flags='"+retval+"'";
if(el=="KB2")
top.main.window.location="welcome.htm";
if(el=="KB21")
top.main.window.location="welcome.htm";
whichEl1 = eval(el + "Child");
for(i=1;i<=numTotal;i++){
whichEl = eval(scores[i] + "Child");
if(whichEl!=whichEl1) {
whichEl.style.display = "none";
}
}
whichEl1 = eval(el + "Child");
if (whichEl1.style.display == "none") {
whichEl1.style.display = "block";
}
else {
whichEl1.style.display = "none";
}
}
else {
whichEl = eval("document." + el + "Child");
for(i=1;i<=numTotal;i++){
whichEl = eval("document." + scores[i] + "Child");
if(whichEl!=whichEl1) {
whichEl.visibility = "hide";
}
}
if (whichEl.visibility == "hide") {
whichEl.visibility = "show";
}
else {
whichEl.visibility = "hide";
}
arrange();
}
}

var retval = "";
function GetArgsFromHref(sHref, sArgName) { var args = sHref.split("?"); if(args[0] == sHref) /*参数为空*/ { return retval; /*无需做任何处理*/ } var str = args[1]; args = str.split("&"); for(var i = 0; i < args.length; i ++) { str = args[i]; var arg = str.split("="); if(arg.length <= 1) continue; if(arg[0] == sArgName) retval = arg[1]; } }onload = initIt;
GetArgsFromHref(window.location.href, "flag");
// --></mce:script>

<link href="../css/css.css" mce_href="css/css.css" rel="stylesheet" type="text/css">
<mce:style type="text/css"><!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url();
}
--></mce:style><style type="text/css" mce_bogus="1">body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url();
}</style>

</head>
<body>
<table width="147" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="147" height="12" valign="bottom">
 </td>
</tr>
<tr>
<td height="12" valign="bottom">
<table width="147" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="22" class="btn">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="24" align="center" background="../images/btn_bg.jpg">
<div id='KB1Parent' class='parent'>
<a href="#" mce_href="#" onclick="expandIt('KB1'); return false" class="white_bold">基础数据</a></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" bgcolor="#FFFFFF">
<div id='KB1Child' class='child'>
<table width="93%" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="1.1.html" mce_href="1.1.html" target="main" class="word1">基本信息1</a></td>
</tr>
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="1.2.html" mce_href="1.2.html" target="main" class="word1">基本信息2</a></td>
</tr>
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="1.3.html" mce_href="1.3.html" target="main" class="word1">基本信息3</a></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td valign="top">
<table width="147" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" class="btn">
<div id='KB2Parent'>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr id="BB1">
<td height="24" align="center" background="../images/btn_bg.jpg">
<a href="#" mce_href="#" onclick="expandIt('KB2'); return false" class="white_bold">数据上报</a></td>
</tr>
<tr id="BB2" style="display: none;" mce_style="display: none;">
<td height="24" align="center" background="../images/btn_bg.jpg">
<a href="#" mce_href="#" onclick="expandIt('KB21'); return false" class="white_bold">数据上报</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr id="strTRJB">
<td valign="top" bgcolor="#FFFFFF">
<div id='KB2Child' class='child'>
<table width="93%" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="2.1.html" mce_href="2.1.html" target="main" class="word1">季报数据1</a></td>
</tr>
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="2.2.html" mce_href="2.2.html" target="main" class="word1">季报数据2</a></td>
</tr>
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="2.3.html" mce_href="2.3.html" target="main" class="word1">季报数据3</a></td>
</tr>
</table>
</div>
</td>
</tr>
<tr id="strTRNB" style="display: none;" mce_style="display: none;">
<td valign="top" bgcolor="#FFFFFF">
<div id='KB21Child' class='child'>
<table width="93%" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="2.6.html" mce_href="2.6.html" target="main" class="word1">年报数据1</a></td>
</tr>
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="2.7.html" mce_href="2.7.html" target="main" class="word1">年报数据2</a></td>
</tr>
<tr>
<td width="12%" height="25" class="word1">
<img src="../images/icon01.jpg" mce_src="images/icon01.jpg" width="4" height="4"></td>
<td width="88%" class="word1">
<a href="2.8.html" mce_href="2.8.html" target="main" class="word1">年报数据3</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<mce:script type="text/javascript"><!--
if(retval=="'jb'"||retval=="") /*初始化及选择季报的情况*/
{
document.getElementById("strTRJB").style.display="block";
document.getElementById("BB1").style.display="block";
document.getElementById("strTRNB").style.display="none";
document.getElementById("BB2").style.display="none";
numTotal=2;scores[1]='KB1';scores[2]='KB2';
}
else
{
document.getElementById("strTRJB").style.display="none";
document.getElementById("BB1").style.display="none";
document.getElementById("strTRNB").style.display="block";
document.getElementById("BB2").style.display="block";
numTotal=2;scores[1]='KB1';scores[2]='KB21';
}
// --></mce:script>
</body>
</html>


 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息