日期:2014-05-16  浏览次数:20394 次

纯js实现的软键盘
(function (jquery) {
    //defined variable
    var currentobj,
    _getdata = function (opts, callback) {
        jquery.ajax({
            type: "post",
            dataType: "text",
            url: opts.requestdataurl,
            cache: false,
            data: { sfbcode: jquery("." + opts.names._codetxt).val() },
            success: callback
        });


    },
    //when code textbox value changed, trigger this event
    _codechangeevent = function (opts) {
        //if codetext onchange trigger
        opts.onkeydown(jquery("." + opts.names._codetxt).val());
        //------------------import---------------------------
        if (opts.onlykeyboard)
            currentobj.val(jquery("." + opts.names._codetxt).val());
        else {
            jquery("." + opts.names._resultsselect).empty();
            //get data from server
            _getdata(opts, function (data) {
                var data = eval("(" + data + ")");
                jquery(data).each(function (index, element) {
                    if (element.name != undefined)
                        jquery("." + opts.names._resultsselect).append("<option value='" + element.name + "'>" + element.name + "</option>");
                });
            });
        }


    },
    //letter button event
    _letterevent = function (opts) {
        jquery("." + opts.names._letterbtn).bind("click",
            function () {
                if (opts.maxlength == null) {
                    jquery("." + opts.names._codetxt).val(jquery("." + opts.names._codetxt).val() + jquery(this).val());
                    _codechangeevent(opts);
                }
                else if (opts.maxlength != null && jquery("." + opts.names._codetxt).val().length < opts.maxlength) {