jQuery .serialize()返回空值

时间:2015-06-12 07:11:53

标签: javascript jquery html

我正在努力帮助别人,但这让我疯了。

场景:一个巨大的javascript文件(14000行),底部有以下两个函数:

function addRoom() {
var roomNumber = document.getElementById("roomNumbers").selectedIndex; //check how many rooms to add
$('#roomGuestForm').html('');//clear div
for (i = 0; i < roomNumber; i++) //loop and add new guest details
{
    var roomDiv = document.createElement('div');
    var roomGuestForm = "<div class='child-guest-select'><label>Guests </label><ul class='small-block-grid-2'><li><i class='fa fa-male'></i><span><input type='text' data-dropdown='adult-guests' aria-controls='adult-guests' aria-expanded='false' value='2' readonly><ul id='adult-guests' class='f-dropdown' data-dropdown-content aria-hidden='true' tabindex='-1'><li><a href='#' title='0'>0</a></li><li><a href='#' title='1'>1</a></li><li><a href='#' title='2'>2</a></li><li><a href='#' title='3'>3</a></li><li><a href='#' title='4'>4</a></li><li><a href='#' title='5'>5</a></li><li><a href='#' title='6'>6</a></li><li><a href='#' title='7'>7</a></li><li><a href='#' title='8'>8</a></li><li><a href='#' title='9'>9</a></li></ul></span><small>18+ Years</small></li><li><i class='fa fa-child'></i><select id='childNumber" + i + "' onchange='addChild("  + i + ")'><option value='none'>0</option><option value='child-num-1'>1</option><option value='child-num-2'>2</option><option value='child-num-3'>3</option><option value='child-num-4'>4</option><option value='child-num-5'>5</option><option value='child-num-6'>6</option></select><small>Under 18</small></li></ul></label><div id='child" + i +"'></div></div>";
    roomDiv.id = 'room' + i;
    $('#roomGuestForm').append(roomDiv);
    $('#room' + i).append(roomGuestForm);
}};

然后

function addChild(index){
var childNumber = document.getElementById("childNumber" + index).selectedIndex; //check how many rooms to add
$('#child' + index).html('');
for (i = 0; i < childNumber; i++) //loop and add new guest details
{
    var roomChildForm = "Room"
    var roomChildForm = "<div class='small-block-grid-6'><small>Child Age</small><select id='childdata" + index + i + "'><option>Under 1</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option></select></div>";   
    $('#child' + index).append(roomChildForm);
}};

然后我尝试像这样序列化表单:

$('#bookingform').submit(function(event) {
// serialize
var str = $( "#bookingform" ).serialize();
console.log(str);
event.preventDefault;});

以下是表格:

<div class="content active" id="book1">
  <form class="filter"  id="bookingform" method="post">
    <div class="row">
      <div class="small-12 columns">
        <h5>Refine Your Dates</h5>
      </div>
    </div>
    <div class="row">
      <div class="small-12 medium-5 large-2 columns">
        <label>
          Check In Date
          <input type="text" class="date-input" id="checkin-date-picker" >
          <small class="parsed-date"></small>
          <small class="error">Please enter a date DD/MM/YYYY</small>
        </label>
      </div>
      <div class="small-12 medium-5 large-2 columns">
        <label>
          Check Out Date
          <input type="text" class="date-input" id="checkout-date-picker" >
          <small class="parsed-date"></small>
          <small class="error">Please enter a date DD/MM/YYYY</small>
        </label>
      </div>
      <div class="small-12 medium-5 large-2 columns">
        <label>
          Rooms
          <select id="roomNumbers" onchange="addRoom()">
            <option value="0" selected="selected">Select</option>
            <option value="1" >1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
          </select>
        </label>
      </div>

      <div id="roomGuestForm" class="small-12 medium-5 large-4 columns child-guest-select" ng-controller="ExampleController"></div>
      <div class="small-12 medium-5 large-2 columns">
        <button type="submit" class="hunt-button" id="roomformbutton">Hunt <i class="fa fa-angle-right"></i></button>
      </div>
</div>


  </form>

问题在于,当我在firebug中查看控制台时,我得到的只是“[]”

一个空数组。我在这做错了什么?为什么我无法控制登录表单值?

非常感谢任何想法。

谢谢

Ĵ

0 个答案:

没有答案