无法调用javascript函数 [英] Unable to call javascript function
本文介绍了无法调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在for循环中有一个javascript函数。我从代码隐藏文件中调用此函数。但即使循环有两次迭代,该函数也只被调用一次。这是代码。
Hi,
I have a javascript function in a for loop. i call this function from code behind file. but the function is only called once even if loop has two iterations. here is the code.
for (int i = 0; i < nodes; i++)
{
ClientScript.RegisterStartupScript(Page.GetType(), "abc", "func('" + xPosition + "','" + yPosition + "','"+nodes+"');", true);
}
功能:
Function:
function func(xPosition, yPosition, nodes)
{
alert(nodes);
svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
// svg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
// svg.setAttribute('version', '1.1');
svg.setAttribute('width', '4cm');
svg.setAttribute('height', '2cm');
svg.setAttribute('x', xPosition);
svg.setAttribute('y', yPosition);
mainSvg.appendChild(svg);
//alert(xPosition + '","' + yPosition);
rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
rect.setAttribute("id", "myrect");
rect.setAttribute("fill", "red");
rect.setAttribute("stroke", "black");
rect.setAttribute("stroke-width", "2");
rect.setAttribute("x", 5);
rect.setAttribute("y", 5);
rect.setAttribute("width", "150");
rect.setAttribute("height", "50");
document.body.appendChild(rect);
svg.appendChild(rect);
}
我将感谢你的帮助。
Usama Javed
I shall be thankful for you help.
Usama Javed
推荐答案
你不能多次注册相同的类型/组合键。通过设置不同的键,您可以多次使用RegisterStatupScript
You can''t registering the same type/key combination more than once. By setting different key you can able to use RegisterStatupScript more than once
Hello Osama,
您遇到严重问题含有以下内容的行:
Hello Osama,
You have a serious problem with the line containing this:
func('" + xPosition + "','" + yPosition + "','"+nodes+"')
您正在尝试注册同样的功能很多次,当然是不允许的。
干杯,
Edo
You are trying to register the same function many times, which of course is not allowed.
Cheers,
Edo
这篇关于无法调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文