Cannot change button value by ajax

前端 未结 4 1608
你的背包
你的背包 2020-12-22 00:51

After applying the http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css and http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js

the text of the

相关标签:
4条回答
  • 2020-12-22 01:08

    Final applying $('#button').prev().text('your new text'); work.

    Just don't understanding why use .prev() before changing the text.

    0 讨论(0)
  • 2020-12-22 01:12

    Can you try this,

     $(".ui-btn-text").text('Processing ...');
    

    Code:

    $(document).ready(function () {
      $('#submit_btn').click(function (e) {        
        e.preventDefault();
        $(".ui-btn-text").text('Processing ...');
        $.ajax({
            cache: false,
            type: "POST",
            dataType: "json",
            data: $('#form1').serialize(),
            url: "echo/json",
            complete: function (HttpRequest, textStatus) {
               $(".ui-btn-text").text('Create');
            }
        });
        return false;
       });
    });
    

    Demo : http://jsfiddle.net/Rz2sJ/4/

    0 讨论(0)
  • 2020-12-22 01:13

    You're working with .button() widget of jQuery Mobile. <button> is converted into a div to give it a new look by jQuery Mobile.

    When doing any changes to <button> or <a>, you need to refresh that element to re-apply styles.

    All you need to do is:

    $(".selector").val('Processing ...').button("refresh");
    

    Demo

    0 讨论(0)
  • 2020-12-22 01:15

    By the time the AJAX callback runs, this as a keyword has lost its context. You need to assign it to a variable to retain the reference. Something like this:

    $(document).ready(function () {
        $('#submit_btn').click(function (e) {
            e.preventDefault();
            var button = $(this);
            button.val('Processing ...');
            $.ajax({
                cache: false,
                type: "POST",
                dataType: "json",
                data: $('#form1').serialize(),
                url: "echo/json",
                complete: function (HttpRequest, textStatus) {
                    button.val('Create');
                }
            });
            return false;
        });
    });
    
    0 讨论(0)
提交回复
热议问题