无法通过ajax更改按钮值 [英] Cannot change button value by ajax

查看:16
本文介绍了无法通过ajax更改按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用后http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.csshttp://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js

按钮的文本不能通过脚本改变$(this).val('new value');

the text of the button cannot be changed by scripting $(this).val('new value');

有没有人有类似的经历并有解决方案?

Do anyone have similar experience and have the solution?

可以从FIDDLE

JQUERY:

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

HTML:

<form action="call.php" method="POST" id="form1" name="form1">
    <input type="text" name="campname" id="campname">
    <textarea id="longdesc" name="longdesc"></textarea>
    <input type="text" name="vercode" id="vercode" />
    <input type="submit" value="Create" id="submit_btn" />
</form>

推荐答案

最终应用 $('#button').prev().text('your new text'); 工作.

只是不明白为什么在更改文本之前使用 .prev().

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

这篇关于无法通过ajax更改按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆