如何通过按钮点击

时间:2018-03-19 08:25:50

标签: javascript html

我有一个登录按钮,当用户点击它时会弹出一个条款和条件对话框并重叠页面上的内容,如下所示

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");                          
                            }
                        }]
            });
        }

我想将此对话框附加到页面上的以下div,而不是弹出所有内容

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

我尝试做以下事情,但它不起作用

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

您的指导将不胜感激。

1 个答案:

答案 0 :(得分:1)

更改此行:

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

$(#mainarea).append(termsHTML);

再试一次。

说明:$('termsHTML').append('#mainarea'); //这里你的选择器错了