0

我需要在 jquery 非模态对话框和文本区域中记录多条消息,

我有一个 jqueryui 自动完成字段,我从中选择一个选项,在选择它登录到 textarea 的选项时。

我还想做的是将它也记录在非模态对话框中。我怎么做?。

这是html。

    <div id="codes">
        <label for="selectcodes"></label>
        <input id="selectcodes" size="25">
        <textarea id="selectcodes-log"></textarea>
    </div>
    <div id="dialog">
        <div>

Here is the javascript, 
/*JSON data, JavaScript object */


     var tag = [
            "abc",
            "efg",
            "hij",
            "klm",
            "nop",
            "qrst"];

    /* this function logs the selected autocomplete option into the textarea */




    function selectcodes_log(message) {


/*this is for logging the code into the textarea */


    $("#selectcodes-log").val(function () {
            return this.value + "codes= " + message + ', '}).prependTo("#selectcodes-log");


/*this is what have tried to log into the non-modal dialog*/

        $("#dialog").val(function(){return this.value  + message +', '}).prependTo( "#dialog");
        }

/*selects multiple autocomplete values */

    $("#selectcodes")
        .bind("keydown", function (event) {
        if (event.keyCode === $.ui.keyCode.TAB && $(this).data("ui-autocomplete").menu.active) {
            event.preventDefault();
        }
    })
`/* jquery ui autocomplete */`

    .autocomplete({
            minLength: 0,
            source: function (request, response) {
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                tag, extractLast(request.term)));
            },
            focus: function () {
                // prevent value inserted on focus
                return false;
            },
            select: function (event, ui) {

                selectcodes_log(ui.item ? +ui.item.value :
                    "Nothing selected, input was " + this.value);

                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                $(this).val("");
                return false;
            }
        });


        /* function for a non modal dialog */
        $(function () {
            $('#dialog').dialog({
                autoOpen: true,
                open: function () {
                    closedialog = 1;
                    $(document).bind('click', overlayclickclose);
                },
                focus: function () {
                    closedialog = 0;
                },
                close: function () {
                    $(document).unbind('click');
                },
                buttons: {
                    Ok: function () {
                        $(this).dialog('close');
                    }
                }
            });
        });

http://jsfiddle.net/pratik24/9VBNd/1/

4

0 回答 0