在JQuery中向生成的选项卡添加内容

时间:2021-12-26 09:47:17

I added this to my already existing JQuery tab:

我将此添加到我现有的JQuery选项卡中:

function createTab(name) {
    // this will add a tab via the standard method
    $("#tabs").tabs("add", "#fragment-4", name);
    $("#fragment-" + name).css("display", "block");
}

my question is, what is the syntax that allows me to create content inside the newly created tab?

我的问题是,允许我在新创建的选项卡中创建内容的语法是什么?

2 个解决方案

#1


Just add the contents to the div you are adding:

只需将内容添加到要添加的div中:

$('#fragment4').html('Contents added via JS');

#2


You can also use the template plugin.

您也可以使用模板插件。

<script id="SomeTemplate" type="text/x-jquery-tmpl">
    <h3>A Header with ${some_variable} in it</h3>
        Your content
</script>

Then inside the .add event in tabs, you can append it to the current tab

然后在选项卡中的.add事件内,您可以将其附加到当前选项卡

$tabs = $("#tabs").tabs({
            add: function( event, ui ) {
                var data_to_pass = {some_variable:"data"};
                $("#SomeTemplate").tmpl(data_to_pass).appendTo(ui.panel);
            }
        });

#1


Just add the contents to the div you are adding:

只需将内容添加到要添加的div中:

$('#fragment4').html('Contents added via JS');

#2


You can also use the template plugin.

您也可以使用模板插件。

<script id="SomeTemplate" type="text/x-jquery-tmpl">
    <h3>A Header with ${some_variable} in it</h3>
        Your content
</script>

Then inside the .add event in tabs, you can append it to the current tab

然后在选项卡中的.add事件内,您可以将其附加到当前选项卡

$tabs = $("#tabs").tabs({
            add: function( event, ui ) {
                var data_to_pass = {some_variable:"data"};
                $("#SomeTemplate").tmpl(data_to_pass).appendTo(ui.panel);
            }
        });

相关文章