【问题标题】:Multipage form in jQuery Mobile loses radio valuesjQuery Mobile 中的多页表单丢失单选值
【发布时间】:2023-03-31 16:38:01
【问题描述】:

我在 jQuery Mobile 中有一个跨越多个页面的表单。我正在使用多页页面,所有页面周围都有一组表单标签。在我将其分成多个页面之前,此表单运行良好。现在它发送文本框数据,但单选按钮的值为空白。有任何解决这个问题的方法吗。以下是带有收音机的 2 页示例。

谢谢!

<div id="1" data-role="page" data-theme="c">
<div data-role="header" data-theme="b" data-position="fixed">
<a data-theme="a" class="ui-btn-right" href="#start" data-role="button" data-icon="back" data-transition="pop" data-rel="dialog" data-inline="true">Start Over</a></div>
<div data-role="content">

<form encoding='multipart/form-data' encType='multipart/form-data'>

<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend><a href="#16pop" data-rel="popup" data-inline="true">Azimuth Verification</a></legend>
<input id="_fid_16_a" type="radio" name="_fid_16" value="Yes"/>
<label for="_fid_16_a">Yes</label><input id="_fid_16_b" type="radio" name="_fid_16" value="No"/>
<label for="_fid_16_b">No</label><input id="_fid_16_c" type="radio" name="_fid_16" value="N/A"/>
<label for="_fid_16_c">N/A</label>
</fieldset>
</div>

</div></div>


<div id="sigemail" data-role="page" data-theme="c">
<div data-role="header" data-theme="b" data-position="fixed">
<a data-theme="a" class="ui-btn-right" href="#start" data-role="button" data-icon="back" data-transition="pop" data-rel="dialog" data-inline="true">Start Over</a></div>
<div data-role="content">


<div data-role="fieldcontain"><label for="_fid_210">What email address would you like to use?</label><input type="text"  name="_fid_210" id="_fid_210" /></div>


<input type="button" value="Submit" data-theme="b" id="sendbtn" onclick="$.mobile.loading( 'show', {text: 'Sending... Please Wait', textVisible: true, theme: 'b'});" />

</form>

<script>
$(document).ready( function(){
    getLocationConstant();
    $('#sendbtn').click(function(){
        $.post(
          'fill.php', 
          $('form').serialize(), 
          function() {
            $.post(
              'https://www.quickbase.com/db/dbName?act=API_AddRecord', 
              $('form').serialize()
            );
            $.mobile.changePage('#successpop', {transition: 'pop', role: 'dialog'});
          }
        ).error(function errHandler() {$.mobile.changePage('#failpop', {transition: 'pop', role: 'dialog'})});
    });
});
</script>

</div></div>

【问题讨论】:

  • 有什么理由需要跨越两个页面的表单?
  • 实际上是 5 页。该表单共有 95 个单选框和 95 个评论框,因此需要稍微拆分一下。任何想法为什么收音机停止发送帖子数据?谢谢。
  • 好的,知道了。请参阅下面的答案。

标签: javascript jquery forms jquery-mobile


【解决方案1】:

实际上,跨多个页面的表单就像一个魅力。
我为你做了一个普通和 jQuery 提交的例子。

该示例共有三个页面:

stub.php的内容:

<?php
    if (isset($_REQUEST)) {
        print_r($_REQUEST);
    }
?>

希望这会有所帮助。

【讨论】:

  • 谢谢perterm!看起来它会起作用。实际上,我最终只是在每个“页面”中放置了打开和关闭表单标签。我没有意识到使用 ajax $('form').serialize() 会准确地发布页面上所有表单的所有数据 - 包括单选。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-21
相关资源
最近更新 更多