从 C# 后面的代码调用 JQuery 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19020303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:01:30  来源:igfitidea点击:

call a JQuery function from code behind in C#

javascriptjqueryc#-4.0code-behind

提问by Fadi Khalil

I want to call this JQuery function from C# code behind but it is not work Here is the JQuery function

我想从后面的 C# 代码中调用这个 JQuery 函数,但它不起作用这是 JQuery 函数

function showDialog(id, title) {
$(id).dialog({
    modal: true, minWidth: 600, title: title
});
$(id).parent().appendTo($("form:first"));

}

}

and here is the code behind which i use

这是我使用的代码

ClientScript.RegisterClientScriptBlock(this.GetType(), "myfunction", "$(document).ready(function(){showDialog('#editCustomer','????? ??????? ????');});", true);

But it is not work

但它不起作用

回答by coder

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "myfunction", "<script type='text/javascript'>myFunction(params...);</script>", true);

回答by Rohaan

try this,

尝试这个,

ScriptManager.RegisterClientScriptBlock(this.Page,this.GetType(), "myfunction", "$(document).ready(function(){showDialog('#editCustomer','????? ??????? ????');});", true);

also try first putting your jQuery function inside $().

也尝试先将您的 jQuery 函数放在 $() 中。