【问题标题】:jquery Mobile Form is not submitting after change event更改事件后jquery Mobile Form未提交
【发布时间】:2015-01-23 05:16:07
【问题描述】:

我正在使用单个表单进行 Jquery 移动应用程序。我在 textarea 中输入了一些文本,并在完全输入文本后用新名称重命名了提交按钮。第一次按下时表单没有提交。它唯一的提交,第二次我按提交按钮。但我需要在第一次按下时提交表单。从我的 Android 手机测试。这是代码,

        <div id="pg_send-sms" data-role="page" data-add-back-btn="true">
        <form name="frm_send-sms" id="frm_send-sms" action="" method="post">
            <div data-role="header" data-position="fixed" data-theme='b'>
                <h1 id='send-sms-header'></h1>
                <a href="#pg_home" data-icon="home">Home</a>
                <a href="" data-role='button' id="history_redirect" data-icon="grid">History</a>
            </div>
            <div data-role="content" id="pg_send-sms_content" class='center-wrapper'>
                <div data-role="fieldcontain">
                <label for="txt_msg_box" style="text-align: left;">Message</label>
                <textarea name="txt_msg_box" class="txt_msg_box" id="txt_msg_box" placeholder="Type your message"></textarea>
                </div>
                <div  data-role="fieldcontain">
                    <input type="submit" name="btn_send_submit" id="btn_send_submit" value="Send" data-theme='b' />
                </div>
            </div>
            <div data-role="footer" data-position="fixed" data-theme='b'>
                <h1 id="send-sms-footer"></h1>
            </div>
        </form>
    </div>

    sendsms.js
    $( "#pg_send-sms" ).on( "pagecreate", function( event ) {

        $('.txt_msg_box').change(changebuttonText);
    });

    function changebuttonText() {   

        $('#btn_send_submit').val("Message");
        $('#btn_send_submit').button("refresh");   
    }
    $("#btn_send_submit").click(function(e){
          alert('button clicked');
          return false;
    });

jsfiddle demo

【问题讨论】:

    标签: jquery jquery-ui jquery-mobile


    【解决方案1】:

    只需将代码包装在 .ready(function(){}) doc here

     $( document ).ready(function() {
        $("#btn_send_submit").click(function(e){
          if($("#btn_send_submit").val("send")){
             $('#btn_send_submit').val("Message");
             $('#btn_send_submit').button("refresh"); 
             alert("im in")
            }
           return false;
           });
        });
    

    您自己测试此代码,或在 JFiddle 中的 FrameWork and Extension 部分,从 &lt;no wrap - in 'body'&gt;&lt;onLoad&gt; 选项中进行选择,我也尝试清理一点代码,删除函数并替换为if statement

    【讨论】:

    • 它提交良好,但按钮文本没有改变。
    • 检查答案的编辑,对我有用,告诉我是否对你有用
    猜你喜欢
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 2014-04-06
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    相关资源
    最近更新 更多