javascript如何实现页间传值

时间:2022-08-26 11:24:17
各位高手们,我想在a页制作一个录入窗口,录完之后点提交按钮会在B页面一列表显示,并且有选择框,选中的某行,还能实行删除操作,各位大侠,小弟的这一设想该如何实现呢?

7 个解决方案

#1


在?后面直接接参数或保存到cookie里面

#2


我只知道模态对话框的。。
dialogArguments可以方法父页面的对象,帮你顶。

#3


先保存到一个obj中然后用Session来传值。
再在B页面取值应该就可以了。

#4


用cookie保存或用url传值

#5


用session\cookie或者URL传参
如果能用数据库的话,可以先保存,在现实页查询再显示就行了

#6


最好用url传过去。用document.URL去取地址栏的值就可以了,如果是子页面到父页面可以用。
window.parent.document.getElementById("tt").value = document.getElementById("t1").value;
tt是父页面中的id,
t1是子页面中的id.

#7


a.html

<!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>
    <title>无标题页</title>
    <script type="text/javascript">
    function LoadWindow2()
{
  URL="b.html";
  loc_x=document.body.scrollLeft+event.clientX-event.offsetX+100;
  loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
  //window.open(URL,"read_notify","height=400,width=550,status=1,toolbar=no,menubar=no,location=no,scrollbars=yes,top=150,left=150,resizable=yes");
  window.showModalDialog(URL,self,"edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:350px;dialogHeight:350px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
}
    </script>
</head>
<body style="text-align:center;">
    <input id="Button1" type="button" value="button" onclick="LoadWindow2()" />
    <input id="Text1" type="text" />
</body>
</html>

b.html
<!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>
    <title>无标题页</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
var parent_window = parent.dialogArguments;
//function Button1_onclick() {
//  parent_window.document.getElementById("Text1").value=parent_window.document.getElementById("Text1").value+'好啊!  ';
//}

function click_user(user_id)
{
  TO_VAL=parent_window.document.getElementById("Text1").value;
//  targetelement=window.document.getElementsByName(user_id);
//  user_name=targetelement.name;
  if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
  {
    if(TO_VAL.indexOf(user_id+",")==0)
    {
       //parent_window.form1.TO_ID.value=parent_window.form1.TO_ID.value.replace(user_id+",","");
       parent_window.document.getElementById("Text1").value=parent_window.document.getElementById("Text1").value.replace(user_id+",","");
      // borderize_off(targetelement);
    }
    if(TO_VAL.indexOf(","+user_id+",")>0)
    {
       //parent_window.form1.TO_ID.value=parent_window.form1.TO_ID.value.replace(","+user_id+",",",");
       parent_window.document.getElementById("Text1").value=parent_window.document.getElementById("Text1").value.replace(","+user_id+",",",");
     // borderize_off(targetelement);
    }
  }
  else
  {
    //parent_window.form1.TO_ID.value+=user_id+",";
    parent_window.document.getElementById("Text1").value+=user_id+",";
   // borderize_on(targetelement);
  }

}

//function borderize_on(targetelement)
//{
// color="#003FBF";
// targetelement.style.borderColor="black";
// targetelement.style.backgroundColor=color;
// targetelement.style.color="white";
// targetelement.style.fontWeight="bold";
//}

//function borderize_off(targetelement)
//{
//  targetelement.style.backgroundColor="";
//  targetelement.style.borderColor="";
//  targetelement.style.color="";
//  targetelement.style.fontWeight="";
//}

// ]]>
</script>
</head>
<body style="text-align:center;">
   <!-- <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />-->
    <table border="1" cellspacing="0" width="100%" class="small" cellpadding="3"  bordercolorlight="#000000" bordercolordark="#FFFFFF">
    <tr class="TableControl">
  <td class="menulines" id="furui" name="1" flag="1" align="center" onclick="javascript:click_user('1')" style="cursor:hand">
  1  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="hexiao" name="2" flag="1" align="center" onclick="javascript:click_user('2')" style="cursor:hand">
  2  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="songdemei" name="3" flag="1" align="center" onclick="javascript:click_user('3')" style="cursor:hand">
  3  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="tanyi" name="4" flag="1" align="center" onclick="javascript:click_user('4')" style="cursor:hand">
  4  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="yanbin" name="5" flag="1" align="center" onclick="javascript:click_user('5')" style="cursor:hand">
  5  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="zengzhi" name="6" flag="1" align="center" onclick="javascript:click_user('6')" style="cursor:hand">
  6  </td>
</tr>

    </table>
    
</body>
</html>

#1


在?后面直接接参数或保存到cookie里面

#2


我只知道模态对话框的。。
dialogArguments可以方法父页面的对象,帮你顶。

#3


先保存到一个obj中然后用Session来传值。
再在B页面取值应该就可以了。

#4


用cookie保存或用url传值

#5


用session\cookie或者URL传参
如果能用数据库的话,可以先保存,在现实页查询再显示就行了

#6


最好用url传过去。用document.URL去取地址栏的值就可以了,如果是子页面到父页面可以用。
window.parent.document.getElementById("tt").value = document.getElementById("t1").value;
tt是父页面中的id,
t1是子页面中的id.

#7


a.html

<!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>
    <title>无标题页</title>
    <script type="text/javascript">
    function LoadWindow2()
{
  URL="b.html";
  loc_x=document.body.scrollLeft+event.clientX-event.offsetX+100;
  loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
  //window.open(URL,"read_notify","height=400,width=550,status=1,toolbar=no,menubar=no,location=no,scrollbars=yes,top=150,left=150,resizable=yes");
  window.showModalDialog(URL,self,"edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:350px;dialogHeight:350px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
}
    </script>
</head>
<body style="text-align:center;">
    <input id="Button1" type="button" value="button" onclick="LoadWindow2()" />
    <input id="Text1" type="text" />
</body>
</html>

b.html
<!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>
    <title>无标题页</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
var parent_window = parent.dialogArguments;
//function Button1_onclick() {
//  parent_window.document.getElementById("Text1").value=parent_window.document.getElementById("Text1").value+'好啊!  ';
//}

function click_user(user_id)
{
  TO_VAL=parent_window.document.getElementById("Text1").value;
//  targetelement=window.document.getElementsByName(user_id);
//  user_name=targetelement.name;
  if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
  {
    if(TO_VAL.indexOf(user_id+",")==0)
    {
       //parent_window.form1.TO_ID.value=parent_window.form1.TO_ID.value.replace(user_id+",","");
       parent_window.document.getElementById("Text1").value=parent_window.document.getElementById("Text1").value.replace(user_id+",","");
      // borderize_off(targetelement);
    }
    if(TO_VAL.indexOf(","+user_id+",")>0)
    {
       //parent_window.form1.TO_ID.value=parent_window.form1.TO_ID.value.replace(","+user_id+",",",");
       parent_window.document.getElementById("Text1").value=parent_window.document.getElementById("Text1").value.replace(","+user_id+",",",");
     // borderize_off(targetelement);
    }
  }
  else
  {
    //parent_window.form1.TO_ID.value+=user_id+",";
    parent_window.document.getElementById("Text1").value+=user_id+",";
   // borderize_on(targetelement);
  }

}

//function borderize_on(targetelement)
//{
// color="#003FBF";
// targetelement.style.borderColor="black";
// targetelement.style.backgroundColor=color;
// targetelement.style.color="white";
// targetelement.style.fontWeight="bold";
//}

//function borderize_off(targetelement)
//{
//  targetelement.style.backgroundColor="";
//  targetelement.style.borderColor="";
//  targetelement.style.color="";
//  targetelement.style.fontWeight="";
//}

// ]]>
</script>
</head>
<body style="text-align:center;">
   <!-- <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />-->
    <table border="1" cellspacing="0" width="100%" class="small" cellpadding="3"  bordercolorlight="#000000" bordercolordark="#FFFFFF">
    <tr class="TableControl">
  <td class="menulines" id="furui" name="1" flag="1" align="center" onclick="javascript:click_user('1')" style="cursor:hand">
  1  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="hexiao" name="2" flag="1" align="center" onclick="javascript:click_user('2')" style="cursor:hand">
  2  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="songdemei" name="3" flag="1" align="center" onclick="javascript:click_user('3')" style="cursor:hand">
  3  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="tanyi" name="4" flag="1" align="center" onclick="javascript:click_user('4')" style="cursor:hand">
  4  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="yanbin" name="5" flag="1" align="center" onclick="javascript:click_user('5')" style="cursor:hand">
  5  </td>
</tr>


<tr class="TableControl">
  <td class="menulines" id="zengzhi" name="6" flag="1" align="center" onclick="javascript:click_user('6')" style="cursor:hand">
  6  </td>
</tr>

    </table>
    
</body>
</html>

相关文章