简体   繁体   English

点击加载jquery标签内容

[英]load jquery tab content on click

I'm new to Jquery and javascript. 我是Jquery和javascript的新手。 I'm using Jquery UI tabs in my as.net project. 我在as.net项目中使用Jquery UI选项卡。 my tabs content is dynamic.so, I use SQL Server to save and retreive them. 我的标签页内容是dynamic.so,因此我使用SQL Server进行保存和检索。 I have a class to build tabs based on special button clicked. 我有一个基于特殊按钮单击来构建选项卡的类。 this is my class: 这是我的课:

 public class TabBuilder{
public string Build(int ServiceId)
{

    string title = " <div class='demo'><div id='tabs' onclick='alert(yes)'><ul>\n";
    string content = "";

    DataTable select = new DataTable();
    ServicesBLL ser = new ServicesBLL();
    select = ser.FormsSelTabs(ServiceId);

     int i = 1;

    foreach (DataRow row in select.Rows)
    {

        title += createTitle(row["LinkName"].ToString(), i);
        content += createContent(row["LinkHref"].ToString(), i);
        i++;
    }
    title += "</ul>\n";
    content += "</div></div>";

    return title + content;
}

private string createTitle(string title, int i)
{

    string htm = "<li><a id='tab{0}' href='#tabs-{1}'>{2}</a></li>\n";
    htm = string.Format(htm, i,i, title);
    return htm;
}

private string createContent(string content, int i)
{
    string htm = "<div id='tabs-{0}'><iframe dir='rtl' frameborder='0' height='600px' width='100%' src='{1}'></iframe></div>\n";
    htm = string.Format(htm, i, content);
    return htm;
}}

in my aspx page I have a literal(LtrTabs) to show tabs and in aspx.cs code I have this code to build tabs: 在我的aspx页面中,我有一个文字(LtrTabs)来显示标签,而在aspx.cs代码中,我具有以下代码来构建标签:

protected void btnEntities_Click(object sender, EventArgs e)
{
    ServiceID = 1;
    TabBuilder tab = new TabBuilder();
    LtrTabs.Text = tab.Build(ServiceID);
 }

I need lazy loading tab but I don't know how to implement it. 我需要延迟加载选项卡,但是我不知道如何实现它。 I saw some examples but none of them use database to load content. 我看到了一些示例,但没有一个示例使用数据库加载内容。

I didn't sift through the server-side code to know for sure, but as long as you have one function that outputs the empty tabs with markup that looks like this: 我没有仔细检查服务器端的代码来确定,但是只要您有一个函数可以输出带有如下标记的选项卡:

http://jqueryui.com/demos/tabs/#Ajax_mode http://jqueryui.com/demos/tabs/#Ajax_mode

Then it's just a matter of populating the hrefs with valid resources. 然后,只需使用有效资源填充href。 On your server side, as long as it's able to recognize incoming requests for HTML contents (no need to send back tabs, etc, just the contents), that's all you need. 在您的服务器端,只要能够识别对HTML内容的传入请求(无需发回标签等,只需发送内容),这就是您所需要的。

To recap: 回顾一下:

  1. Function to return the HTML with empty tabs. 返回带有空标签的HTML的函数。 Alternatively, if this doesn't need to be dynamic, just write it as HTML; 另外,如果不需要动态,只需将其编写为HTML; no point complicating things with unecessary logic. 没有必要将不必要的逻辑复杂化。

  2. Function to return the content of the tabs. 返回标签内容的函数。

How you distinguish between the two is really up to you. 如何区分这两者完全取决于您。 POST/GET variables, different URLs... however your application is being built. POST / GET变量,不同的URL ...但是正在构建您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM