简体   繁体   English

单击按钮时如何将对话框添加到页面的主div中

[英]How to append a dialog into a main div on your page on button click

I have a log in button that when a user clicks on it a terms and condition dialog pops up and overlaps the contents on a page as follows 我有一个登录按钮,当用户单击它时,将弹出一个条款和条件对话框,并与页面上的内容重叠,如下所示

TermsSuccess: function (result, context) {

            var topTerms = findSetByInArray(result.Data, 'ParentId', 0);
            var termsHTML = '<div id="terms"><ul class="termsList">';
            for (var i = 0; i < topTerms.length; i++) {
                var cls = (topTerms[i].isNew) ? 'newTerm' : 'Term';
                termsHTML += '<li id=' + topTerms[i].ID + ' class=' + cls + '>'
                termsHTML += topTerms[i].PageIndex + '. ' + topTerms[i].Detail;
                termsHTML += getChildrenTerms(result.Data, topTerms[i].ID, topTerms[i].PageIndex + '. ');
                termsHTML += '</li>';
            }
            termsHTML += '</ul></div>';
            $(termsHTML).dialog({
                modal: true,
                resizable: false,
                width: 400,
                height: 600,
                closeOnEscape: false,
                open: function (event, ui) {
                    $(this).parent().children().children('.ui-dialog-titlebar-close').hide();
                },
                title: "Terms & Conditions",
                buttons: [{
                    text: "Decline",
                    "class": 'btnDialog',
                    click: function () {
                        $(this).dialog("close");
                    }
                },
                        {
                            text: "Accept",
                            "class": 'btnDialog',
                            click: function () {
                                betEvents.btnAccept_onClick();
                                $(this).dialog("close");                          
                            }
                        }]
            });
        }

I want this dialog to be appended to the following div on the page instead of it poping up over all the contents 我希望将此对话框添加到页面上的以下div上,而不是在所有内容上弹出

<div id="mainarea"></div>

i tried to do something as the following but it doesnt work 我试图做以下事情,但它不起作用

function onClick(){
if $("#btnLogin").click(function(){
$('termsHTML').append('#mainarea');
});
}

your guidance will be appreciated. 您的指导将不胜感激。

Change this line: 更改此行:

$('termsHTML').append('#mainarea');

to

$(#mainarea).append(termsHTML);

and try again. 然后再试一次。

Explanation: $('termsHTML').append('#mainarea'); 说明: $('termsHTML').append('#mainarea'); // here your selector is wrong //这里的选择器错误

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

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