在动态添加的行中将javasript属性添加到单元格。 [英] Adding javasript property to a cell in dynamically added rows.

查看:105
本文介绍了在动态添加的行中将javasript属性添加到单元格。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我是javascripts的新手,


i使用addRow scipt动态地向表中添加行。


one第N行中的单元格(比如cell2)需要超链接到另一个脚本。


例如:

Hi.. i am new to javascripts,

i am using a addRow scipt to add rows to a table dynamically.

one of the cells(say cell2) in a Nth row needs to be hyperlinked to another script.

for example:

展开 | 选择 | Wrap | 行号

推荐答案


嗨..我是javascripts的新手,


i我正在使用addRow scipt动态地向表中添加行。


第N行中的一个单元格(比如cell2)需要是例如:


函数addRow()//添加行脚本

{

var tbl = document.getElementById(" table");

var numRows = tbl.rows.length;

var newRow = tbl.insertRow(numRows);


// ID

var secondCell = newRow.insertCell(2);

var box2 = document.createElement(''TD'');

//文本框

var txtInp2 = document.createElement(''input'');

txtInp2.name =" IDs";

txtInp2.type =''text'';

txtInp2.value ="" ;;

// image

var link2 = document.createElement(''< a href ="#" onClick =" javascript :Popup(这个)">'');


var image2 = document.createElement(''< IMG align = middle border = 0 src =''find.gif''> ;'');

link2.appendChild(image2);

box2.appendChild(txtInp2);
box2.appendChild(link2);

secondCell.appendChild(box2);


//我将图片附加到链接, txtInp2并链接到框,box2到// secondCell。

}

函数弹出窗口(obj)

{

currentRowIndex = obj.parentElement.parentElement.rowIndex;

obj = document.form.IDs;

if(obj.length!= null)

{

window.Id = document.form.IDs(currentRowIndex-1);

}

else

{

window.Id = obj;

}


var urlString =< something> ;;

image = window.open(urlString," width = 480,height = 230,status");

image.focus();

} $ / $

我的问题是,如果已经定义了表(如果在表格的第一行中指定的href到PopUp(),在HTML中声明,则链接到PopUp(obj)正在工作,但如果我使用addRow()动态地向表中添加行,则链接到n中的PopUp()添加的新行没有工作,

它给出了一个错误信息告诉对象预期和或parentElement.parentElement; ,或长度为空或不是对象


我不知道如何在

var link2 = document中指定''this''。 createElement(''< a href ="#" onClick =" javascript :Popup(this)">'');


PLZ帮助......!
Hi.. i am new to javascripts,

i am using a addRow scipt to add rows to a table dynamically.

one of the cells(say cell2) in a Nth row needs to be hyperlinked to another script.

for example:

function addRow() // the add row script
{
var tbl=document.getElementById("table");
var numRows=tbl.rows.length;
var newRow=tbl.insertRow(numRows);

//IDs
var secondCell=newRow.insertCell(2);
var box2=document.createElement(''TD'');
//textbox
var txtInp2=document.createElement(''input'');
txtInp2.name="IDs";
txtInp2.type=''text'';
txtInp2.value="";
//image
var link2=document.createElement(''<a href="#"onClick="javascript:Popup(this)">'');

var image2=document.createElement(''<IMG align=middle border=0 src=''find.gif''>'');
link2.appendChild(image2);
box2.appendChild(txtInp2);
box2.appendChild(link2);
secondCell.appendChild(box2);

// i am appending image to link , txtInp2 and link to the box, and box2 to //secondCell.
}
function Popup(obj)
{
currentRowIndex = obj.parentElement.parentElement.rowIndex;
obj = document.form.IDs;
if(obj.length != null)
{
window.Id=document.form.IDs(currentRowIndex-1);
}
else
{
window.Id=obj;
}

var urlString = <something>;
image=window.open(urlString,"width=480,height=230, status");
image.focus();
}

My problem is, if the table is already defined(if href to PopUp() specified in first row of table,declared in HTML, then link to PopUp(obj) is working , but if i add rows to the table dynamically using addRow(), the links to PopUp() in the new rows added are not working,
it gives a error msg telling either "object expected" or "parentElement.parentElement" ,or "length is null or not an object"

I dont know how to specify the ''this'' in
var link2=document.createElement(''<a href="#"onClick="javascript:Popup(this)">'');

PLZ help...!



试试这个:

try this:

展开 | 选择 | Wrap < span class =codeDivider> | 行号


Heya,Sandeep。欢迎来到TSDN!


发布源代码时请使用CODE标签。请在下次发布时查看页面右侧的REPLY GUIDELINES。
Heya, Sandeep. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.


对不起..我尝试了你的建议,但它没有用。


我的表单元素的完整代码是这样的,也可能是这里有一些错误。

sorry..I tried what u suggested, but it is not working.

My full code with form element goes like this,might be there is some error in these too.

展开 | 选择 | 换行 | 行号


这篇关于在动态添加的行中将javasript属性添加到单元格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆