如何从后面的C#代码中调用jQuery [英] How to call a jquery from c# code behind

查看:81
本文介绍了如何从后面的C#代码中调用jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个jquery选项卡,每个选项卡都有一个按钮,用于加载数据库中数据的预览.但是,每次完成时,它始终集中在第一个选项卡上.我希望它专注于执行代码后选择的选项卡.为此,我应该调用.focus()API,但是如何从后面的代码中调用.focus()API?

谢谢,

Franco

Hi,

I have a jquery tab, each tab has a button that loads a preview of data from the database. But everytime it finishes it always focuses on the first tab. I want it to focus on the tab that I selected after it executes the code.For that I should call the .focus() API, but how do I call the .focus() API from code behind?

Thanks,

Franco

推荐答案

没有这样的东西:后面的代码"是指服务器端的代码;它仅处理HTTP请求并产生HTTP响应,仅此而已.而且"jQuery"实际上意味着"JavaScript库",因此它只能在客户端上用作JavaScript代码.

您需要获得的效果是可能的,但与调用"无关. HTTP响应仅生成HTML文件,该文件可以带有外部实体(每个实体都在单独的HTTP请求中加载)或嵌入式JavaScript代码.因此,您只需生成一些JavaScript代码,该代码就可以执行某些操作.特别是,它可以在文档准备好后立即集中精力,这是jQuery常用的技术:

There is no such thing: "code behind" is referred to the code on server side; it only handles HTTP request and produces HTTP response, nothing else. And "jQuery" actually means "JavaScript library", so it works as JavaScript code, only on the client side.

The effect you need to get is possible, but it has nothing to do with "call". HTTP response simply generates the HTML file, which can comes with external entities (each loaded on separate HTTP request) or embedded JavaScript code. So, you simply generate some JavaScript code, and this code can do something. In particular, it can focus something as soon as document is ready, which is a usual jQuery technique:


(文档).ready(功能(){ myTextInput =
(document).ready(function(){ myTextInput =


(" ); // ,假设文本框为< input type ="text" id ="someId">因此,它具有id ="someId"属性,用于标识 myTextInput.focus(); });
("#someId"); //assuming the text box is <input type="text" id="someId" > so, it has the attribute id="someId", for identification myTextInput.focus(); });



也可以在其他任何DOM元素事件中处理我,这取决于所需的功能.

请参阅:
http://docs.jquery.com/How_jQuery_Works [ http://api.jquery.com/focus/ [ http://en.wikipedia.org/wiki/HTTP [ http://en.wikipedia.org/wiki/Web_application [ http://en.wikipedia.org/wiki/Asp.net [ http://www.asp.net/get-started [ http://www.w3schools.com/aspnet/default.asp [ http://msdn.microsoft.com/en-us/library/aa479011.aspx [ ^ ].

—SA



I can also be handled in any other DOM element event, depending on required functionality.

Please see:
http://docs.jquery.com/How_jQuery_Works[^],
http://api.jquery.com/focus/[^].

This question suggests that you really need to learn how Web works. I would advise to start from the very beginning:
http://en.wikipedia.org/wiki/HTTP[^],
http://en.wikipedia.org/wiki/Web_application[^],
http://en.wikipedia.org/wiki/Asp.net[^],
http://www.asp.net/get-started[^],
http://www.w3schools.com/aspnet/default.asp[^].

This is a useful article on using JavaScript with ASP.NET:
http://msdn.microsoft.com/en-us/library/aa479011.aspx[^].

—SA


这篇关于如何从后面的C#代码中调用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆