从 C# 调用 jQuery 函数
我有下面的函数,需要从 C# 调用,
$('.image-cropper').each(linkUp);
任何人都可以解释它是如何完成的。我尝试使用下面的代码
String csname1 = "PopupScript";
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type=\"text/javascript\"> $('.image-cropper').each(linkUp); </");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname1, cstext2.ToString(), false);
,但它不起作用。
I have the function below which needs to be called from C#
$('.image-cropper').each(linkUp);
Can anyone explain how it could be done. I tried using the below code
String csname1 = "PopupScript";
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type=\"text/javascript\"> $('.image-cropper').each(linkUp); </");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname1, cstext2.ToString(), false);
but it did not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实应该在 jQuery 就绪函数中调用您的代码,即:
您的代码无法正常工作的可能原因是,当您的代码运行时,image-cropper 元素不在 DOM 中。
You should really be calling your code inside the jQuery ready function ie:
The likely reason your code wasn't working was that the image-cropper elements weren't in the DOM when your code was run.