![](/img/trans.png)
[英]Call C# method from another page in javascript function with jQuery
[英]Call C# method from another class using JavaScript/jQuery
我有一個jQuery方法,在單擊時返回div
的文本。 此方法位於.js
文件中。 我想使用另一個類中的方法,該方法使用被點擊的div中的文本作為參數。
的JavaScript / jQuery的:
$(document).on('click', '#clicked div', function () {
var temp = $(this).html();
temp = temp.replace('<span>', '').replace('</span>', '');
// someMethod(temp);
});
Class.cs
:
public string someMethod(string str){
return str;
}
如何從JavaScript文件中訪問此方法?
使該類靜態並添加該方法,即someMethod,然后對該方法進行ajax調用
public static class Yourclass
{
public static string someMethod(string str)
{
return str;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.