更改事件后,jquery Mobile Form未提交

时间:2015-01-23 05:16:08

标签: jquery jquery-ui jquery-mobile

我正在使用单一表单进行Jquery Mobile Application。我在textarea中输入了一些文本,并在完全输入文本后重命名了提交按钮,新的名称。表单在第一次按下时没有提交。它只提交,第二次我按下提交按钮。但我需要在第一次按下时提交表单。来自我的Android Mobile.Here是代码,

        <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

1 个答案:

答案 0 :(得分:-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;
       });
    });

FrameWork and Extension部分自己或JFiddle中测试此代码,从<no wrap - in 'body'><onLoad>选项中选择,同时我尝试清理一点代码,删除该功能并替换为if statement