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

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

问题描述

申请后, 的http:// code .jquery.com /移动/ 1.3.2 / jquery.mobile-1.3.2.min.css 的http:// code .jquery.com /移动/ 1.3.2 / jquery.mobile-1.3.2.min.js

按钮的文字不能被脚本修改 $(本).VAL(新价值);

做任何人有类似的经验,并有解决办法吗?

DEMO可以从试图 FIDDLE

JQUERY:

  $(文件)。就绪(函数(){
    $('#的submit_btn)。点击(函数(五){
        即preventDefault();
        $(本).VAL(处理...);
        $阿贾克斯({
            缓存:假的,
            键入:POST,
            数据类型:JSON,
            数据:$('#Form1的)序列化()。
            网址:回声/ JSON
            完成:功能(Htt的prequest,textStatus){
                $(本).VAL(创建);
            }
        });
        返回false;
    });
});
 

HTML:

 <形式的行动=call.php方法=POSTID =Form1的NAME =Form1的>
    <输入类型=文本名称=campnameID =campname>
    < textarea的ID =LONGDESCNAME =LONGDESC>< / textarea的>
    <输入类型=文本名称=版本codeID =版本code/>
    <输入类型=提交值=创建ID =的submit_btn/>
< /形式GT;
 

解决方案

最后的申请 $('#键)preV()文本(新文字); 的工作。

只是不理解为什么要用。preV()之前更改文本。

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 button cannot be changed by scripting $(this).val('new value');

Do anyone have similar experience and have the solution?

DEMO can be tried from 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>

解决方案

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

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

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

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