我在获取完整显示的父节点id时遇到了一些问题。
我使用一个循环来检测表中的div元素,然后让它找到父TD节点,并在另一个变量中获取该节点的id。
我的问题是,在这个循环中,我用这个TD id在数组中建立了一个变量,当它打印的时候,第一次只显示第一个字符,第二次只显示第二个字符,之后的任何时候都会是空的。
如果我从变量中删除数组,它将打印整个id,但每次循环运行时,它都会将旧的值重命名为最近的值。
有人能帮我解决这个问题吗?
感谢您的帮助,谢谢您的帮助。
下面是正在编写的函数
test.save = function () {
var cell = rd = REDIPS.drag,
page1a = document.getElementById(redips.p1a),
divs = TableID.getElementsByTagName('DIV'),
rd.find_parent('TD', rd.obj), //parent cell
st = cell.id, //parent cell ID
st,
id, //div id
cid, //cell id
ccid,
concatenator, // concatenate oDiv ID
query = '',
div, // current DIV element
i; // loop variable
for (i = 0; i < divs.length; i++) {
// set current DIV element
div = divs[i];
// set current TD ID
cid = st[i];
if (div.className.indexOf('drag') > -1) {
//takes two characters off of the DIV ID only
concatenator = div.id.substring(0, div.id.length - 2);
// creates the query through the loop
query += cid + '=' + concatenator + ' ';
}
}
if (query.length > 0) {
document.getElementById('message').innerHTML = query;
}
};以下是指向使用TD ID为http://stevenschemers.com/beta1/的数组的版本的链接
这里有一个指向不使用TD ID数组的版本的链接:http://stevenschemers.com/beta2/
我还注意到,如果运行两次,它看起来就像循环,因为'i‘将计数为0,2,4,6,或者有时是1,3,5,7
发布于 2012-05-18 07:32:03
// loop goes through each DIV element collected on the left side of page 1
for (i = 0; i < divs.length; i++) {
// set current DIV element
div = divs[i];
if (div.className.indexOf('drag') > -1) {
// sets current cell ID for dropped div
cid = rd.find_parent('TD', div).id;
concatenator = div.id.substring(0, div.id.length - 2);
// creates the query through the loop
querya += cid + '=' + concatenator + '&';
qc++;
}
}https://stackoverflow.com/questions/10544107
复制相似问题