从C#调用jQuery函数 [英] Calling jQuery function from C#
本文介绍了从C#调用jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的功能,需要从C#调用
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);
但是没有用.
推荐答案
您应该真正在jQuery ready函数中调用代码,即:
You should really be calling your code inside the jQuery ready function ie:
$(function() {
$('.image-cropper').each(linkUp);
});
您的代码无法正常工作的可能原因是,当您运行代码时,图像裁剪器元素不在DOM中.
The likely reason your code wasn't working was that the image-cropper elements weren't in the DOM when your code was run.
这篇关于从C#调用jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文