父页面和模态子页面页面传值 以name遍历标签
2015-01-11 17:38
176 查看
分为两个页面Father.aspx和module.aspx.分别是父页面和弹出的模态页面。
Father.aspx页面的关键代码为:
var str = "";// 此变量为公共变量。为了接收子页面的值
var win = window.showModalDialog('module.aspx', window, "resizable:no;scrollbars:no;status:no;help:no;dialogWidth:400px;dialogHeight:300px");
// 此语句为打开模态窗体。注意:第二个参数必须为window
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>测试模式对话框</title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var str = "";
function tianjia() {
var win = window.showModalDialog('module.aspx', window, "resizable:no;scrollbars:no;status:no;help:no;dialogWidth:400px;dialogHeight:300px");
}
function setValue() {
document.getElementById("dates").value = str;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>
弹出模式窗口</label>
<input type="button" id="winMod" value="弹出模式窗口" onclick="tianjia()" />
<input type="text" id="dates" />
</div>
</form>
</body>
</html>
模态页module
关键代码为:
var txt;//记录返回值
var main = window.dialogArguments;// 获得窗体参数
main.str = checkeds;//获取返回值 str为父页面变量
main.setValue();// 调用父页面的js方法 对变量值进行设置
window.close();// 关闭模态窗口
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var txt;
var main = window.dialogArguments;
function init() {
var isSelected = "<%=items %>";
var arrays = isSelected.split(',');
var boxs = document.getElementsByName("1");
for (var j = 0; j < arrays.length; j++) {
for (var i = 0; i < boxs.length; i++) {
if (boxs.item(i).id == arrays[j]) {
boxs.item(i).checked = true;
break;
}
}
}
}
$(window).load(function () {
init();
});
function checkSelect() {
var checkeds = "";
var arrCheckBox = document.getElementsByName("1");
for (var i = 0; i < arrCheckBox.length; i++) {
if (arrCheckBox.item(i).checked == true) {
checkeds += arrCheckBox.item(i).id + ",";
}
}
// alert(checkeds);
main.str = checkeds;
main.setValue();
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="sure" value="提交" onclick="checkSelect()" />
<table style="width: 80%;">
<tr>
<th style="width: 33%;">
上午
</th>
<th style="width: 33%;">
中午
</th>
<th style="width: 33%;">
下午
</th>
</tr>
<tr>
<td>
<input id="11" name="1" type="checkbox" />
</td>
<td id="121">
<input id="12" name="1" type="checkbox" />
</td>
<td>
<input id="13" name="1" type="checkbox" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Father.aspx页面的关键代码为:
var str = "";// 此变量为公共变量。为了接收子页面的值
var win = window.showModalDialog('module.aspx', window, "resizable:no;scrollbars:no;status:no;help:no;dialogWidth:400px;dialogHeight:300px");
// 此语句为打开模态窗体。注意:第二个参数必须为window
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>测试模式对话框</title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var str = "";
function tianjia() {
var win = window.showModalDialog('module.aspx', window, "resizable:no;scrollbars:no;status:no;help:no;dialogWidth:400px;dialogHeight:300px");
}
function setValue() {
document.getElementById("dates").value = str;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>
弹出模式窗口</label>
<input type="button" id="winMod" value="弹出模式窗口" onclick="tianjia()" />
<input type="text" id="dates" />
</div>
</form>
</body>
</html>
模态页module
关键代码为:
var txt;//记录返回值
var main = window.dialogArguments;// 获得窗体参数
main.str = checkeds;//获取返回值 str为父页面变量
main.setValue();// 调用父页面的js方法 对变量值进行设置
window.close();// 关闭模态窗口
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var txt;
var main = window.dialogArguments;
function init() {
var isSelected = "<%=items %>";
var arrays = isSelected.split(',');
var boxs = document.getElementsByName("1");
for (var j = 0; j < arrays.length; j++) {
for (var i = 0; i < boxs.length; i++) {
if (boxs.item(i).id == arrays[j]) {
boxs.item(i).checked = true;
break;
}
}
}
}
$(window).load(function () {
init();
});
function checkSelect() {
var checkeds = "";
var arrCheckBox = document.getElementsByName("1");
for (var i = 0; i < arrCheckBox.length; i++) {
if (arrCheckBox.item(i).checked == true) {
checkeds += arrCheckBox.item(i).id + ",";
}
}
// alert(checkeds);
main.str = checkeds;
main.setValue();
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="sure" value="提交" onclick="checkSelect()" />
<table style="width: 80%;">
<tr>
<th style="width: 33%;">
上午
</th>
<th style="width: 33%;">
中午
</th>
<th style="width: 33%;">
下午
</th>
</tr>
<tr>
<td>
<input id="11" name="1" type="checkbox" />
</td>
<td id="121">
<input id="12" name="1" type="checkbox" />
</td>
<td>
<input id="13" name="1" type="checkbox" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
相关文章推荐
- 页面中存在标签 name=aa 同时存在js函数aa
- 【转】模态窗口的父页面向子页面传值
- iframe的name属性用法(配合a标签的target属性实现页面局部刷新)
- a 标签 name 属性 页面定位 (一)
- 页面自适应<meta name="viewport">标签设置
- WEB页面标签属性:ID &amp; NAME
- js 实现获取name 相同的页面元素并循环遍历
- 在JSP中使用el标签传递值(两个jsp页面之间传值)
- jsp 页面中用struts2 标签遍历集合(list map)
- Java中返回的对象无法再jsp页面中循环遍历到标签上
- struts2 通过前台标签name属性将值传到后台,没有name属性传值,则后台对象有默认值,不为null。
- html在vs2010中与aspx页面传值resquest.form["name"]
- Struts2:通过action标签向页面传值
- JSP页面遍历对象集合,map,数组等,Struts的s标签和c标签的区别
- Action和页面间迭代标签等传值
- spring3 页面form标签 报错 Neither BindingResult nor plain target object for bean name "company"
- js实现列表页面和模态页面传值
- Struts2:通过action标签向页面传值
- 两个.aspx 页面传值 Request.QueryString["NAME"]
- jsp页面传值到action,命名name,对象自动接收