我创建的代码将与facebook添加朋友一样发送消息列表(归档To :)。 代码在FrontPage中创建,也在那里进行了测试,功能有限,正如FrontPage预览一样,并且它正在工作...... 然后它在IE 7和IE 8甚至IE 9中进行了测试,它也有效...... 还在FireFox,Chrome和Safari中进行了测试,它也正在运行......
然后,我将此代码发送给朋友,他说这不起作用...... 我一遍又一遍地看着代码,我找不到可能出错的地方......
代码信息:
topolje - 包含用户列表的div,当您点击特定用户时,它调用函数addnewto('username')
howbig - 用于计算新创建的用户字段大小的背景div,因此可以调整输入字段的大小以适应用户列表和输入的字段......
newone - 输入你开始输入用户名的地方,它显示以...开头的用户名
getRefToDiv(id_of_element) - 在不同浏览器中按其ID查找元素
这是代码:
var skup = new Array();
var skup2 = new Array();
function addnewto(user)
{
var i = 777777;
var userform = '';
var k = 0;
var velicina = 23;
getRefToDiv('topolje').style.height = "23px";
for ( j = 0; j < skup.length; j++ ) {
if ( skup[j] == "" ) {
i = j;
}
else
{
userform2 = '<font id="tekst' + j + '" name="tekst' + j + '" style="background: #8BBC40; border:1px solid #808080; -moz-border-radius: 3px; border-radius: 3px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px" face="Tahoma" size="2" color="#FFFFFF">' + skup2[j] + ' |<span onclick="';
userform2 += "this.parentNode.parentNode.removeChild(getRefToDiv('tekst" + j + "-1')); this.parentNode.parentNode.removeChild(this.parentNode); skup.splice(" + j + ",1); skup2.splice(" + j + ",1); setTimeout('getsize();', 10);;";
userform2 += '" style="cursor: pointer"> x </span></font><span id="tekst' + j + '-1" name="tekst' + j + '-1"> </span>';
var mast = getRefToDiv('howbig');
var duzina = 0;
mast.innerHTML = userform + userform2;
duzina = mast.clientWidth;
if ( duzina > 405 ) {
userform += "<br>" + userform2;
velicina += 21;
getRefToDiv('topolje').style.height = velicina + "px";
}
else
{
userform += userform2;
}
}
}
if ( i = 777777 ) {
i = skup.length;
}
skup[i] = 'tekst' + i;
skup2[i] = user;
userform2 = '<font id="tekst' + i + '" name="tekst' + i + '" style="background: #8BBC40; border:1px solid #808080; -moz-border-radius: 2px; border-radius: 2px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px" face="Tahoma" size="2" color="#FFFFFF">' + user + ' |<span onclick="';
userform2 += "this.parentNode.parentNode.removeChild(getRefToDiv('tekst" + i + "-1')); this.parentNode.parentNode.removeChild(this.parentNode); skup.splice(" + i + ",1); skup2.splice(" + i + ",1); setTimeout('getsize();', 10);";
userform2 += '" style="cursor: pointer"> x </span></font><span id="tekst' + i + '-1" name="tekst' + i + '-1"> </span>';
var mast = getRefToDiv('howbig');
var duzina = 0;
mast.innerHTML = userform + userform2;
duzina = mast.clientWidth;
if ( duzina > 405 ) {
userform += "<br>" + userform2;
velicina += 21;
getRefToDiv('topolje').style.height = velicina + "px";
}
else
{
userform += userform2;
}
getRefToDiv('topolje').innerHTML = userform + '<input type="text" onblur="if ( this.value.length < 3 ) { proveri(0); } else { proveri(2); }" onfocus="if ( this.value.length < 2 ) { proveri(1); }" onkeyup="if ( this.value.length > 2 ) { proveri(this.value); }" style="border: 1px solid #FFFFFF; width: 10px; font-family:Verdana; font-size:10pt; color:#8BBC40;" id="newone" name="newone">';
reorder();
}
function reorder()
{
var i = 777777;
var userform = '';
var userformx = '';
var k = 0;
var velicina = 23;
getRefToDiv('topolje').style.height = "23px";
for ( j = 0; j < skup.length; j++ ) {
if ( skup[j] == "" ) {
i = j;
}
else
{
userform2 = '<font id="tekst' + j + '" name="tekst' + j + '" style="background: #8BBC40; border:1px solid #808080; -moz-border-radius: 3px; border-radius: 3px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px" face="Tahoma" size="2" color="#FFFFFF">' + skup2[j] + ' |<span onclick="';
userform2 += "this.parentNode.parentNode.removeChild(getRefToDiv('tekst" + j + "-1')); this.parentNode.parentNode.removeChild(this.parentNode); skup.splice(" + j + ",1); skup2.splice(" + j + ",1); setTimeout('getsize();', 10);;";
userform2 += '" style="cursor: pointer"> x </span></font><span id="tekst' + j + '-1" name="tekst' + j + '-1"> </span>';
var mast = getRefToDiv('howbig');
var duzina = 0;
mast.innerHTML = userform + userform2;
duzina = mast.clientWidth;
if ( duzina > 405 ) {
userform += "<br>" + userform2;
userformx = userform2;
velicina += 21;
getRefToDiv('topolje').style.height = velicina + "px";
}
else
{
userform += userform2;
userformx += userform2;
}
}
}
getRefToDiv('topolje').innerHTML = userform + '<input type="text" onblur="if ( this.value.length < 3 ) { proveri(0); } else { proveri(2); }" onfocus="if ( this.value.length < 2 ) { proveri(1); }" onkeyup="if ( this.value.length > 2 ) { proveri(this.value); } else { proveri(1); }" style="border: 1px solid #FFFFFF; width: 10px; font-family:Verdana; font-size:10pt; color:#8BBC40;" id="newone" name="newone">';
var mast = getRefToDiv('howbig');
var duzina = 0;
mast.innerHTML = userformx;
duzina += mast.clientWidth;
var duzina2 = 400 - duzina;
getRefToDiv('newone').style.width = duzina2 + 'px';
}
我正在研究这个问题很长时间,我无法弄清楚这一点...... 如果你发现可能出错的东西,请告诉我......
感谢。
答案 0 :(得分:4)
我甚至不知道它在任何浏览器中是如何工作的。
此:
if ( i = 777777 ) {
i = skup.length;
}
应该是这样的:
if (i === 777777) {
i = skup.length;
}
这是代码中常见的错误,称为“意外分配”。也就是说,除非您总是希望条件块评估为true,否则您的代码等同于:
i = 777777;
i = skup.length;
我确信你不是故意的。我建议切换一个WYSIWYG编辑器,转而使用一个好的IDE来指出这些内容(例如,NetBeans,一旦我将代码粘贴到一个新的空白javascript文件中,就会突出显示这一行)。
而且,这只是众多问题中的一个问题。有关解决所有其他问题的说明,请参阅我对该问题的评论。
答案 1 :(得分:0)
问题出在第217行和第42行