通过 javascript 访问动态创建的控件 - ASP.NET
我的页面中有一个 JavaScript 函数,通过它我可以将页面中的一些元素设置为“JQuery UI droppable”。
function setDroppableTargets()
{
$(.cssDockZone).droppable();
}
但是 cssDockZone 类的元素是在用户交互时动态创建的。因此,在后面的代码中,我首先创建控件,最后注册一个调用 setDroppableTargets() 的脚本块。
//set droppable targets
ClientScript.RegisterClientScriptBlock(this.GetType(), "setDroppableTargets", "setDroppableTargets()", true);
但是在创建控件之前调用了 javascript 函数,尽管我在最后注册了脚本(创建控件之后),并且通过获取类名为“.cssDockZone”的元素来交叉检查它,并将其设置为 0。
$(.cssDockZone).length
任何想法?
I've a JavaScript function in my page through which i make some elements in the page as 'JQuery UI droppable'.
function setDroppableTargets()
{
$(.cssDockZone).droppable();
}
But the elements with the class cssDockZone is created dynamically upon user interaction. So in the code behind i create the control first and finally at the end i register a scriptblock which calls setDroppableTargets().
//set droppable targets
ClientScript.RegisterClientScriptBlock(this.GetType(), "setDroppableTargets", "setDroppableTargets()", true);
But the javascript function is invoked before the controls are created eventhough i register the script at the end (after creating the controls) and i cross checked it by getting the elements with class name '.cssDockZone' and i getting it as 0.
$(.cssDockZone).length
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我用的是“.”将它们分配给控件时在 css 类名之前。愚蠢的。删除“.”修好了。
I was using '.' before the css class name while assigning them to the control. Silly. Removing the '.' fixed it.