第3个:
假如你的父页面是这样的
function go()
{
alert("go");
}
//-->
</SCRIPT>
<iframe name='ifm' src='child.html'></iframe>你在child.htm里调go函数这样调top.go();
假如你的父页面是这样的
function go()
{
alert("go");
}
//-->
</SCRIPT>
<iframe name='ifm' src='child.html'></iframe>你在child.htm里调go函数这样调top.go();
<SCRIPT LANGUAGE="JavaScript">
<!--
function get()
{
var tableid = document.getElementById("tableid");
var trid = document.getElementById("trid");
alert(tableid.rows[0].cells[1].innerText);
}
//-->
</SCRIPT>
<TABLE border=1 id="tableid">
<tr height=21 id='trid' >
<td nowrap class="tabletd" height=21 ><input type="radio" name="select" ><span>3</span></td>
<td><div>1111</div></td>
<td><div>2222</div></td>
<td><div>3333</div></td>
<td><div>4444</div></td>
<td><div>5555</div></td>
</tr>
</TABLE>
<INPUT TYPE="button" value='get' onclick="get();">
建议你去看看DHTML四个可读写的属性
innerText, outerText, innerHTML, outerHTML你第一个问题,那个函数你准备执行什么事情?
if( document.all && typeof( document.all ) == "object" )
obj.fireEvent("onclick");
else
{
var e = document.createEvent("MouseEvent");
e.initEvent("click", true,true );
obj.dispatchEvent(e);
}
}
2.
function iterator(table)
{
var td = table.getElementsByName("td");
for(i=0;i<td.length;i++)
{
alert(td[i].firstChild.innerHTML);
}
}
3. 将父窗口对象传过去 showModalDialog('dialog.htm',window,);
在子窗口用
var parentWin = window.dialogArguments取得父窗口对象
//调用函数
parentWin.functionName();
//赋值
parentWin.document.getElementById("textbox").value="ice_berg16";
做法是这样的:
function fastpost(){
var obj=new Object();
obj.name="李四";
window.showModalDialog ("fastpos.html",obj,"dialogHeight=145Px;dialogWidth=385Px");
}
这个函数打开一个页面(我们叫子页面吧)。我现在的做法是在子页面里写一个函数遍历父页面里的一个tabA的表格,并且,在行里找到符合条件的记录后,就执行当前行的一个onclick事件,选定这一行。实际上是一个“快速定位功能”
在原来两个onmouseover()与onmouseout()里加了一段
var trobj = event.srcElement.parentElement;
if(trobj.tagName != "TR")
{//取得行的对象
trobj = trobj.parentElement;
}
修改后程序:<HEAD><!-- 定义样式 -->
<style>
tr.trover
{
background-color:#FF0000;
}
tr.trout
{
background-color:#3399FF;
}
td.tdclass
{
background-color:#33FFFF;
}
</style>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
global_order = 2;//前面的id自增
function save()
{
trd=document.all.tabA.insertRow();
var newtr = document.all.tabA.rows;
newtr[newtr.length-1].onclick = function()//呼叫tr里的onclick函数
{
tronclick();
};
newtr[newtr.length-1].onmouseover = function()//呼叫tr里的onmouseover函数
{
var trobj = event.srcElement.parentElement;
if(trobj.tagName != "TR")
{//取得行的对象
trobj = trobj.parentElement;
}
// alert(trobj);
onClass(trobj);
};
newtr[newtr.length-1].onmouseout = function()//呼叫tr里的onmouseout函数
{
var trobj = event.srcElement.parentElement;
if(trobj.tagName != "TR")
{//取得行的对象
trobj = trobj.parentElement;
}
outClass(trobj);
};
v1=document.all("input1").value;
v2=document.all("input2").value;
v3=document.all("input3").value;
v4=document.all("input4").value;
v5=document.all("input5").value; trd.insertCell().innerHTML="<input type='radio' name='select' value='"+v1+"'"+"><SPAN>"+global_order+"</SPAN>";
trd.insertCell().innerHTML="<SPAN calss=tdclass>"+v1+"</SPAN>"; trd.cells[trd.cells.length-1].className = "tdclass";//改变单个td的样式,注意会覆盖tr的样式 trd.insertCell().innerHTML="<SPAN>"+v2+"</SPAN>";
trd.insertCell().innerHTML="<SPAN>"+v3+"</SPAN>";
trd.insertCell().innerHTML="<SPAN>"+v4+"</SPAN>";
trd.insertCell().innerHTML="<SPAN>"+v5+"</SPAN>";
document.all("input1").value="";
document.all("input2").value="";
document.all("input3").value="";
document.all("input4").value="";
document.all("input5").value="";
global_order++;
}
function tronclick()
{
alert("响应tronclick函数");
}
function onClass(obj)
{//onmouseover
obj.className ="trover";
}
function outClass(obj)
{//onmouserout
obj.className ="trout";
}
//-->
</SCRIPT><BODY>
<INPUT TYPE="text" NAME="input1" value="AAA"><br/>
<INPUT TYPE="text" NAME="input2" value="BBB"><br/>
<INPUT TYPE="text" NAME="input3" value="CCC"><br/>
<INPUT TYPE="text" NAME="input4" value="DDD"><br/>
<INPUT TYPE="text" NAME="input5" value="EEE"><br/><table id=tabA border=1>
<tr height=21 onclick="tronclick();" onMouseOver="onClass(this);" onMouseOut="outClass(this);" >
<td nowrap height=21 ><input type="radio" name="select"><SPAN>1</SPAN></td>
<td nowrap><div>fdgfg</div></td>
<td nowrap><div>fgfdsg</div></td>
<td nowrap><div>fdsgfdgdsg</div></td>
<td nowrap><div>fdsgfg</div></td>
<td nowrap><div>fsg</div></td>
</tr>
</table>
<INPUT TYPE="button" value="go" onclick="save();">
</BODY>
http://peipei3000.jishuqi.com/reg.asp
http://www.goofar.com/?ID=634664011139
========================================
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:base/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>表格测试</title>
<script type='text/javascript' src='/kk/dwr/engine.js'></script>
<script type='text/javascript' src='/kk/dwr/util.js'></script>
<script type='text/javascript' src='/kk/dwr/interface/DynaTable.js'></script>
<style type="text/css">
Body{
color:#555555 ;font-size:12px;line-height:150%
}
.tabletd{font-size:12px;color:26548b;line-height:150%}
#controlbar
{
border:1px solid #ccc;
padding:3px;
} .text{
border : 1px solid #c2c2c2;
}
.trover{
background-color:#ddf7ff;
}
.trout{
background-color:#ffffff;
}
.td{
color:#555555;font-size:12px;
}
</style>
<script language="javascript">
var tds=false;
var current_tr=false;
var str_return="";
function tronclick(obj){
document.all("input1").readOnly=true;
document.all("input2").readOnly=true;
document.all("input3").readOnly=true;
document.all("input4").readOnly=true;
document.all("input5").readOnly=true;
document.all("input6").readOnly=true;
obj.cells[0].children[0].checked=true;
document.all("input1").value=obj.cells[0].children[1].innerText;
document.all("input2").value=obj.cells[1].children[0].innerText;
document.all("input3").value=obj.cells[2].children[0].innerText;
document.all("input4").value=obj.cells[3].children[0].innerText;
document.all("input5").value=obj.cells[4].children[0].innerText;
document.all("input6").value=obj.cells[5].children[0].innerText;
if(tds!=false){
obj.style.backgroundColor="#c0dde2";
tds.style.backgroundColor="";
}
obj.style.backgroundColor="#c0dde2";
tds=obj;
current_tr=obj;
}
function add(){
document.all("input1").value="";
document.all("input1").readOnly=false;
document.all("input2").value="";
document.all("input2").readOnly=false;
document.all("input3").value="";
document.all("input3").readOnly=false;
document.all("input4").value="";
document.all("input4").readOnly=false;
document.all("input5").value="";
document.all("input5").readOnly=false;
document.all("input6").value="";
document.all("input6").readOnly=false;
document.all("hid1").value="add"
}
function edit(){
document.all("input1").readOnly=true;
document.all("input2").readOnly=false;
document.all("input3").readOnly=false;
document.all("input4").readOnly=false;
document.all("input5").readOnly=false;
document.all("input6").readOnly=false;
document.all("hid1").value="edit";
} function save(){
action=document.all("hid1").value;
alert(action);
if(action=="add"){
trd=document.all.tabA.insertRow();
var newtr=document.all("tabA").rows;
newtr[newtr.length-1].onclick=function(){
tronclick(newtr[newtr.length-1]);
};
newtr[newtr.length-1].onmouseover=function(){
var trobj=event.srcElement.parentElement();
if(trobj.tagName!="TR"){
trobj=trobj.parentElement;
}
//trmover(newtr[newtr.length-1]);
trmover(trobj);
};
newtr[newtr.length-1].onmouseout=function(){
var trobj=event.srcElement.parentElement();
if(trobj.tagName!="tr"||trobj.tagName!="TR"){
trobj=trobj.parentElement;
}
trmout(trobj);
//trmout(newtr[newtr.length-1]);
}; v1=document.all("input1").value;
v2=document.all("input2").value;
v3=document.all("input3").value;
v4=document.all("input4").value;
v5=document.all("input5").value;
v6=document.all("input6").value; trd.insertCell().innerHTML="<td nowrap class='tabletd' height=21 nowrap><input type='radio' name='select' value='"+v1+"'"+"><SPAN>"+v1+"</SPAN></td>";
trd.insertCell().innerHTML="<td><SPAN>"+v2+"</SPAN></td>";
trd.insertCell().innerHTML="<td><SPAN>"+v3+"</SPAN></td>";
trd.insertCell().innerHTML="<td><SPAN>"+v4+"</SPAN></td>";
trd.insertCell().innerHTML="<td><SPAN>"+v5+"</SPAN></td>";
trd.insertCell().innerHTML="<td><SPAN>"+v6+"</SPAN></td>";
document.all("input1").value="";
document.all("input2").value="";
document.all("input3").value="";
document.all("input4").value="";
document.all("input5").value="";
document.all("input6").value="";
document.all("input1").readOnly=false;
document.all("input2").readOnly=false;
document.all("input3").readOnly=false;
document.all("input4").readOnly=false;
document.all("input5").readOnly=false;
document.all("input6").readOnly=false;
DynaTable.addSaveRecord("'"+v1+"'","'"+v2+"'","'"+v3+"'","'"+v4+"'","'"+v5+"'","'"+v6+"'","'"+action+"'",addreturn);
}else if(action=="edit"){
current_tr.cells[1].children[0].innerText=document.all("input2").value;
current_tr.cells[2].children[0].innerText=document.all("input3").value;
current_tr.cells[3].children[0].innerText=document.all("input4").value;
current_tr.cells[4].children[0].innerText=document.all("input5").value;
current_tr.cells[5].children[0].innerText=document.all("input6").value;
document.all("input2").readOnly=true;
document.all("input3").readOnly=true;
document.all("input4").readOnly=true;
document.all("input5").readOnly=true;
document.all("input6").readOnly=true;
v1=document.all("input1").value;
v2=document.all("input2").value;
v3=document.all("input3").value;
v4=document.all("input4").value;
v5=document.all("input5").value;
v6=document.all("input6").value;
DynaTable.editSaveRecord("'"+v1+"'","'"+v2+"'","'"+v3+"'","'"+v4+"'","'"+v5+"'","'"+v6+"'","'"+action+"'",editreturn);
}
}
//回调函数
function addreturn(data){
alert(data);
}
function editreturn(data){
alert(data);
}
function deletereturn(data){
alert(data);
}
//TR的鼠标有关函数
function trmover(obj){
obj.className="'trover'";
}
function trmout(obj){
obj.className="'trout'";
}
function deletea(){
if(current_tr==false){
alert("请选择要删除的记录!");
}
var id=current_tr.cells[0].children[1].innerText;
if(id!=null){
DynaTable.deleteRecord("'"+id+"'",deletereturn);
current_tr.removeNode(true);
document.all("input1").value="";
document.all("input2").value="";
document.all("input3").value="";
document.all("input4").value="";
document.all("input5").value="";
document.all("input6").value="";
}
}
function fastpost(){
window.showModalDialog("fastpos.html",window,"dialogHeight=145Px;dialogWidth=385Px");
}
</script>
</head><body topmargin="0" leftmargin="0">
<br>
<table width="481" height="19" border="0" align="center" cellpadding="0" cellspacing="0" id="controlbar">
<tr>
<td>
<button onclick="add()">添加 </button> <button onclick="save()">保存</button> <BUTTON onclick="deletea()">删除</BUTTON> <BUTTON onclick="edit();">修改</BUTTON> <BUTTON onclick="fastpost();">快速定位</BUTTON>
</td>
</tr>
</table>
<div style="position:absolute; left:139px; width=300px; width: expression(tabA.offsetWeight+30);height:98px; overflow:scroll; border:1 solid; background-color:white; scrollbar-face-color:#D4D0C8; scrollbar-shadow-color:white; scrollbar-highlight-color:#F6F5F4; scrollbar-3dlight-color:white; scrollbar-darkshadow-color:#86837E; scrollbar-track-color:#F6F5F4; scrollbar-arrow-color:#86837E; width: 529px;">
<table cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" width="521" align="center" bordercolorlight="0a426b" border="1" id="tabA" name="tabA">
<thead>
<tr height="24px">
<td bgColor=#cad0e2 width="95" height="24px">
<div style="font-size:12px; color:#26548b;line-height:150%" align="center"><font color="#000000">序号</font></div>
</td>
<td bgColor=#cad0e2 width="74" height="24px">
<div style="font-size:12px; color:#26548b;line-height:150%" align="center"><font color="#000000">标志</font></div>
</td>
<td bgColor=#cad0e2 width="90" height="24px">
<div style="font-size:12px; color:#26548b;line-height:150%" align="center"><font color="#000000">打印</font></div>
</td>
<td bgColor=#cad0e2 width="90" height="24px">
<div style="font-size:12px; color:#26548b;line-height:150%" align="center"><font color="#000000">计划日期</font></div>
</td>
<td bgColor=#cad0e2 width="79" height="24px">
<div style="font-size:12px; color:#26548b;line-height:150%" align="center"><font color="#000000">类别</font></div>
</td>
<td bgColor=#cad0e2 width="79" height="24px">
<div style="font-size:12px; color:#26548b;line-height:150%" align="center"><font color="#000000">品名</font></div>
</td>
</tr>
</thead>
<tbody>
<tr height=21 onclick="tronclick(this)" onMouseOver="this.className='trover'" onMouseOut="this.className='trout'" >
<td nowrap class="tabletd" height=21 ><input type="radio" name="select"><SPAN>1</SPAN></td>
<td nowrap><div>fdgfg</div></td>
<td nowrap><div>fgfdsg</div></td>
<td nowrap><div>fdsgfdgdsg</div></td>
<td nowrap><div>fdsgfg</div></td>
<td nowrap><div>fsg</div></td>
</tr>
<tr nowrap height=21 onclick="tronclick(this)" onMouseOver="this.className='trover'" onMouseOut="this.className='trout'">
<td nowrap class="tabletd" height=21 nowrap><input type="radio" name="select" ><span>2</span></td>
<td><div>gf</div></td>
<td><div> </div></td>
<td><div>fgsfg</div></td>
<td><div> </div></td>
<td><div>fgsfdg</div></td>
</tr>
<tr height=21 onclick="tronclick(this)" onMouseOver="this.className='trover'" onMouseOut="this.className='trout'">
<td nowrap class="tabletd" height=21 ><input type="radio" name="select" ><span>3</span></td>
<td><div>gfdg</div></td>
<td><div>fsgfdg</div></td>
<td><div>dsg</div></td>
<td><div>vcbsrdger</div></td>
<td><div>fgetr</div></td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p> </p>
<p> </p>
<table width="539" height="71" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#c2c2c2">
<tr>
<input type="hidden" name="hid1" id="hid1" value="add">
<td width="46" height="22" bgcolor="#f7f7f7"><div style="font-size:12px">序号</div></td>
<td width="212" bgcolor="#ffffff"><input type="text" id="input1" name="input1" class="text" readonly="true"/></td>
<td width="63" bgcolor="#f7f7f7"><div style="font-size:12px">标志</div></td>
<td width="197" bgcolor="#ffffff"><input type="text" id="input2" name="input2" class="text" readonly="true"/></td>
</tr>
<tr>
<td height="22" bgcolor="#f7f7f7"><div style="font-size:12px">打印</div></td>
<td bgcolor="#ffffff"><input type="text" id="input3" name="input3" class="text" readonly="true"/></td>
<td bgcolor="#f7f7f7"><div style="font-size:12px">计划日期</div></td>
<td bgcolor="#ffffff"><input type="text" id="input4" name="input4" class="text" readonly="true"/></td>
</tr>
<tr>
<td height="21" bgcolor="#f7f7f7"><div style="font-size:12px">类别</div></td>
<td height="20" bgcolor="#ffffff"><input type="text" id="input5" name="input5" class="text" readonly="true"/></td>
<td height="21" bgcolor="#f7f7f7"><div style="font-size:12px">品名</div></td>
<td height="21" bgcolor="#ffffff"><input type="text" id="input6" name="input6" class="text" readonly="true"/></td>
</tr>
</table>
<p> </p>
</body>
</html>
如果是那样的话
你是要一直呼叫被选中的那个tr的onclick函数呢
还是要改变被选中的tr,并且同时呼叫被选中tr的onclik函数吗
是呀,我在做一个快速定位的功能,就是执行了符合条件的行的onclick()事件来选中这条记录,但现在的问题,怎么让滚动条移动,在表格显示区域里能显示选中的记录,这是一个问题。还有一个问题,就是添加的并且不是最后一行的tr,没有onclick(),onmouseover(),onmouseout()事件。这问题怎么解决呢。
这个已经解决了,我昨天测试过了,你拿我上面发的那个代码去看看就知道怎么解决了我再看看你发的代码
此函数用于控制滚动条的滚动情况,可以有true|false参数可以选择使用.
obj为要显示的对象,可以是控件,行,超链接等.另外提醒:
DHTML中对多个控件使用相同的id时,会自动形成一个数组.
在你的帮助下,快速定位的实现了,通过快速定位函数是可以在那些添加并且不是最后一行的执行onclick()事件。但还在依然存在
"有一个问题,就是添加的并且不是最后一行的tr,没有onclick(),onmouseover(),onmouseout()事件。这问题怎么解决呢。",请那位大哥帮分析一下是啥原因
主要是这行代码在原来两个onmouseover()与onmouseout()里加了一段
var trobj = event.srcElement.parentElement;
if(trobj.tagName != "TR")
{//取得行的对象
trobj = trobj.parentElement;
}
trd.insertCell().innerHTML="<td nowrap class="" onclick="funA()" onmouseover="funcB()" onmouseout="funC()">.....</td>";
按你的方法早试过了,不行!
此函数是将控件的指定事件绑定到指定函数,希望能对你有帮助.
注意在js和vbs中,使用方法是不同的.
js的例子
<PUBLIC:ATTACH EVENT="ondetach" ONEVENT="cleanup()" />
<SCRIPT LANGUAGE="JScript">
attachEvent ('onmouseover', Hilite);
attachEvent ('onmouseout', Restore);
function cleanup()
{
detachEvent ('onmouseover', Hilite);
detachEvent ('onmouseout', Restore);
}
function Hilite()
{
if (event.srcElement == element)
{
normalColor = style.color;
runtimeStyle.color = "red";
runtimeStyle.cursor = "hand";
}
}
function Restore()
{
if (event.srcElement == element)
{
runtimeStyle.color = normalColor;
runtimeStyle.cursor = "";
}
}
</SCRIPT>
vbs的例子
<HTML>
<BODY ONLOAD="setupEventHandler()" LANGUAGE="VBS">
<SCRIPT LANGUAGE="VBS">
function setupEventHandler()
set fpchgBackground = getRef("chgBackground")
call mySpan.attachEvent("onclick", fpChgBackground)
end function
function chgBackground()
document.bgColor = "lemonchiffon"
end function
</SCRIPT>
<SPAN ID="mySpan">SPAN</SPAN>
</BODY>
</HTML>