有一个文本框(ID="name"),后面有一个按钮,点击这个按钮,谈出一个框(用JS做的)。框里面有一张表,我想点击这张表其中一个字段如:名称,怎么才能把这个名称传回给(ID="name")这个文本框了???
解决方案 »
- 服务器标记的格式不正确?请教大家!
- 求推荐 asp.net mvc 2.0 图书
- 简单的JS问题,大家进.在线等,速度结帐
- asp.net可不可以远程抓取的,就像asp小偷,哪位兄弟有例子没有
- 使用DAAB更新数据出现的错误!!!!!!!!!!!!!!
- 如何当页面加载的时候执行Button_Click事件!
- 。net初级问题:我的datagrid怎么运行时无法看见呢?别的button什么的没有问题,我的是。net beta 2,谢谢先:)
- 起怪的问题!大家来看一看!
- 如何获取另外一个类里的变量值!新手入们急!
- datagrid又有问题了
- ASP.NET弹出新窗口更新数据问题?
- 一个朋友的自定义函数
然后将相应的字段值cell赋给文本框.
例如:
parent.document.getElementById("name").value = cell[0].value ....
var a = window.showModalDialog(...);
弹出窗口上的JS
window.returnValue =formValue;//formValue你要返回的值
这个框是div还window,还是iframe
例子1:div的<html>
<head>
<script type="text/javascript">
function showWindow()
{
//document.all.winchild.style = "display:yes";
document.getElementById("winchild").style.display="block";
}
function returnValue()
{
document.getElementById("text2").value = document.getElementById("text1").value;
document.getElementById("winchild").style.display="none";
}
</script>
</head>
<body>
<div id="winchild" style="display:none">
<input type="textbox" value="" id="text1"/>
<input type="button" value="ok" id="button1" onclick="returnValue()"/>
</div>
<div id="main">
<input type="textbox" value="" id="text2"/>
<input type="button" value="open" id="button2" onclick="showWindow()"/>
</div>
</body>
</html>例子2:窗口
1.html<html>
<head>
<script type="text/javascript">
function showWindow()
{
window.open("2.html");
}
function returnValue(rtValue)
{
document.getElementById("text2").value = rtValue;
}
</script>
</head>
<body><div id="main">
<input type="textbox" value="" id="text2"/>
<input type="button" value="open" id="button2" onclick="showWindow()"/>
</div>
</body>
</html>2.html<html>
<body>
<div id="main">
<input type="textbox" value="" id="text1"/>
<input type="button" value="ok" id="button1" onclick="javascript:window.opener.returnValue(document.getElementById('text1').value)"/>
</div>
</body>
</html>
function OpenGoodsName(obj)
{
var iHeight="500px";
var iWidth="786px";
var iTop = event.screenY - event.offsetY + 20;
var iLeft = event.screenX - event.offsetX - 4 - 175;
var returnValue;
returnValue=window.showModalDialog("Default8.aspx",window,"dialogHeight="+iHeight+";dialogWidth="+iWidth+";dialogTop="+iTop+"px;dialogLeft="+iLeft+"px;help=0;center=1;resizable=0;status=0;scroll=0");
if(returnValue!=null)
{
obj.value=returnValue;
}
return false;
}
之后 在给需要的单元格添上 事件
类似于单元格.attributes.add(onclick,"window.openner.document.getElementById('name').value=this.innerHTML");
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//第i列
e.Row.Cells[i].Attributes.Add("onclick",
"window.dialogArguments.document.getElementById('name').value=this.innerText;");
}
}也可以在gridview 的绑定事件后写
foreach (GridViewRow gr in gv.Rows)
{
gr.Cells[i].Attributes.Add("onclick",
"window.dialogArguments.document.getElementById('name').value=this.innerText;"); }
foreach(GridViewRow row in gridview.rows )
{
foreach(TableCell cell in row.cells )
{
//todo
}
}
<head>
<script type="text/javascript">
function showWindow()
{
//document.all.winchild.style = "display:yes";
document.getElementById("winchild").style.display="block";
}
function returnValue()
{
document.getElementById("text2").value = document.getElementById("text1").value;
document.getElementById("winchild").style.display="none";
}
</script>
</head>
<body>
<div id="winchild" style="display:none">
<input type="textbox" value="" id="text1"/>
<input type="button" value="ok" id="button1" onclick="returnValue()"/>
</div>
<div id="main">
<input type="textbox" value="" id="text2"/>
<input type="button" value="open" id="button2" onclick="showWindow()"/>
</div>
</body>
</html>
在RowDataBound事件里写的么?
{
foreach(TableCell cell in row.cells )
{
//我不确定Sandy945 所说的用showModalDialog 打开的页 也不能用window.openner 来获得引用 ,我没有试过,你具体自己调试下cell.attributes.add(onclick,"window.openner.document.getElementById('name').value=this.innerHTML"); }
}
在弹出的页面按钮里面写js:onclick="opener.document.getEleMentById('name').value=this.value"js代码是直接可以写到事件里面的。