选择值后显示消息框

时间:2017-12-13 21:16:49

标签: javascript jquery ajax dialog messagebox

我想在某个文本字段中选择ajax自动完成值时显示一个消息框。我正在使用jquery-confirm js库。这是我的代码。

                    select: function( event, ui ) {
                        console.log( ui.item.value );
                        nic= ui.item.value;
                        $("#msgbox").open();
                        return false;
                    }

    $("#msgbox").confirm({
        title: 'Entry Found',
        content: 'msg',
        lazyOpen:true,
        buttons: {
            confirm: function () {
                $.alert('Confirmed!');
            },
            cancel: function () {
                $.alert('Canceled!');
            },

ps:我对js和这些jquery的东西很新。:)

2 个答案:

答案 0 :(得分:0)

试试吧。而不是'确认'使用'对话'。在'选择'里面这样打电话。

$("#msgbox").dialog("open");

$("#msgbox").dialog({
    title: 'Entry Found',
    content: 'msg',
    autoOpen: false,
    modal: true,
    lazyOpen:true,
    buttons: {
        confirm: function () {
            alert('Confirmed!');},
        cancel: function () {
            alert('Canceled!');}
}
});

答案 1 :(得分:0)

好吧我发现问题,source应该在jquery $("#nic").autocomplete({ minLength:5, source : function(request, response) { $.ajax({ url: "ajaxautocomplete.html", type: "Post", data:JSON.stringify({"nic": request.term}), contentType: "application/json", dataType: "json", success : function(data) { response($.map(data.patient, function (patient) { return{ label: patient.nic, id: patient.id, } })) } }); }, select: function( event, ui ) { //msg confirm box return true } }); 之外,这里是完整的代码;

execute block

并且对话框无效,我使用了jquery-confirm框。