簡體   English   中英

ajax調用后jQuery numpad無法正常工作

[英]Jquery numpad not working after ajax call

我正在使用jQuery numpad。 它是完美的,但在ajax調用后無法正常工作。 我已經厭倦了('單擊功能和其他功能等。但我沒有得到結果。對不起我的英語不好:)擴展鏈接: http : //a.kabachnik.info/jquery-numpad.html

數字鍵javascript:

// Set NumPad defaults for jQuery mobile. 
// These defaults will be applied to all NumPads within this document!
$.fn.numpad.defaults.gridTpl = '<table class="table modal-content"></table>';
$.fn.numpad.defaults.backgroundTpl = '<div class="modal-backdrop in"></div>';
$.fn.numpad.defaults.displayTpl = '<input type="text" class="form-control" />';
$.fn.numpad.defaults.buttonNumberTpl =  '<button type="button" class="btn btn-default"></button>';
$.fn.numpad.defaults.buttonFunctionTpl = '<button type="button" class="btn" style="width: 100%;"></button>';
$.fn.numpad.defaults.onKeypadCreate = function(){$(this).find('.done').addClass('btn-primary');};

// Instantiate NumPad once the page is ready to be shown
$(document).ready(function(){
    $('#text-basic').numpad();
    $('#password').numpad({
        displayTpl: '<input class="form-control" type="password" />',
        hidePlusMinusButton: true,
        hideDecimalButton: true 
    });
    $('#numpadButton-btn').numpad({
        target: $('#numpadButton')
    });
    $('#numpadButton-btn2').numpad({
        target: $('#numpadButton2')
    });
    $('#numpad4div').numpad();
    $('#numpad4column .qtyInput').numpad();

    $('#numpad4column tr').on('click', function(e){
        $(this).find('.qtyInput').numpad('open');
    });
});

AJAX調用重裝小鍵盤和其他區域:

$("#toplamtutar").on('click', '#button-transaction2', function () {
    $.ajax({
        url: 'index.php?route=marketing/affiliate/addtransaction&token=<?php echo $token; ?>&affiliate_id=<?php echo $affiliate_id; ?>',
        type: 'post',
        dataType: 'json',
        data: 'description=' + encodeURIComponent($('#tab-transaction input[name=\'description\']').val()) + '&amount=' + encodeURIComponent($('#tab-transaction input[name=\'amount\']').val()),
        beforeSend: function() {
            $('#button-transaction2').button('loading');
        },
        complete: function() {
            $('#button-transaction2').button('reset');
        },
        success: function(json) {
            $('.alert').remove();

            if (json['error']) {
                 $('#tab-transaction').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
            }

            if (json['success']) {
                $('#tab-transaction').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');

                $('#transaction').load('index.php?route=marketing/affiliate/transaction&token=<?php echo $token; ?>&affiliate_id=<?php echo $affiliate_id; ?>');
                $("#toplamtutar").load(location.href+" #toplamtutar>*",""); 
                $('#tab-transaction input[name=\'amount\']').val('-<?php echo $balance; ?>');
                $('#tab-transaction input[name=\'description\']').val('Hesap Alındı');          
            }
        }
    });
});

HTML:

<div class="input-group" style="border-top: 1px solid #ededed; padding-top: 15px; padding-bottom: 15px;">
  <input type="text" name="tasimano" value="" placeholder="Masa No" style="background-color: #f0f0f0;" id="numpadButton" class="form-control" aria-describedby="numpadButton-btn" />
  <span class="input-group-btn">
    <button class="btn btn-default" id="numpadButton-btn" type="button"><i class="fa fa-calculator"></i></button>
  </span>
</div>

創建一個函數來初始化元素上的數字鍵盤

    $(document).ready(function(){
        initializeNumpad(); // Instantiate NumPad once the page is ready to be shown
        $('#numpad4column tr').on('click', function(e){
            $(this).find('.qtyInput').numpad('open');
        });
    });

    function initializeNumpad() {
        $('#text-basic').numpad();
        $('#password').numpad({
                        displayTpl: '<input class="form-control" type="password" />',
                        hidePlusMinusButton: true,
                        hideDecimalButton: true 
        });
        $('#numpadButton-btn').numpad({
            target: $('#numpadButton')
        });
        $('#numpadButton-btn2').numpad({
            target: $('#numpadButton2')
        });
        $('#numpad4div').numpad();
        $('#numpad4column .qtyInput').numpad();
     }

在ajax成功回調中調用相同的函數

$.ajax({
    url: 'index.php?route=marketing/affiliate/addtransaction&token=<?php echo $token; ?>&affiliate_id=<?php echo $affiliate_id; ?>',
    ....
    ....
    success: function(json) {
        $('.alert').remove();
        .....
        if (json['success']) {
            ....
            $("#toplamtutar").load(location.href+" #toplamtutar>*",""); 
            $('#tab-transaction input[name=\'amount\']').val('-<?php echo $balance; ?>');
            $('#tab-transaction input[name=\'description\']').val('Hesap Alındı');          
            initializeNumpad();// call here to reinitialize
        }
    }
});

它將插件事件重新附加到刷新的元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM