与Chrome的Jquery不兼容问题

时间:2012-05-25 18:49:50

标签: javascript jquery html google-chrome incompatibility

我遇到了头疼的情况。当我选中选择选项(05/30/2012 EQ)时,我无法单击选择按钮来提交操作,但我应该可以单击它。问题出现在Chrome和I.E上,但它适用于FF。我认为这是一个Jquery不兼容问题。我附上了一些代码如下:

  function $recalcSelection($checkbox) {
    $selectActionList.find("option").each(function() {
      $optionLength = $table.find("td.actioncolumn input:checked").length;
      if($optionLength <= 0) {
        $(this).attr("disabled", true);
      } else if($optionLength == 1) {
        $(this).attr("disabled", false);
      } else {
        if(
          $(this).val() == "editAppointment" ||
          $(this).val() == "copyAppointment" ||
          $(this).val() == "viewShowList" ||
          $(this).val() == "viewScheduledTimes")
        {
          $(this).attr("disabled", true);
        } else {
          $(this).attr("disabled", false);
        }
      }
    });

    if($selectActionList.find("option:selected").attr('disabled')) {
      $selectActionList.find("option:enabled").eq(0).attr("selected", true);
    }

    if($selectActionList.find("option:enabled").length <= 0) {
      $selectActionButton.attr("disabled", true);
    } else {
      $selectActionButton.attr("disabled", false);
    }
  }

$ selectActionButton是提交按钮,$ selectactionlist是选择列表。我尝试打印($ selectActionList.find(“选项:启用”)。长度在Chrome中,它是0.但是当我在FF中打印它时,它是7.任何人都可以帮我找出原因吗?我会这样感谢它。谢谢

enter image description here

我附上了一些HTML表格如下:

<table id="appointmentTable">
  <thead>
    <tr class="headerrow">
      <th class="actioncolumn"></th>
      <th class="datecolumn">Date</th>
      <th class="earliesttimecolumn">Start Time</th>

      <th class="clientnamecolumn">Client</th>
      <th class="locationcolumn">Location</th>
      <th class="roomcolumn">Rooms</th>
      <th class="typecolumn">Type</th>
      <th class="filledtimescolumn">Filled Times</th>
    </tr>

  </thead>

  <tbody> 

      <tr class=" hiddenrow" appointmentid="15166">
        <td class="actioncolumn"><input type="checkbox" name="appointmentids[]" value="15166" /></td>
        <td class="datecolumn"><span title="1338094800"></span><a href="?action=viewDailyUsers&date=05/27/2012&clients[]=8" title="View Appointments on 05/27/2012">05/27/2012</a></td>
        <td class="earliesttimecolumn"></td>
        <td class="clientnamecolumn">CPH</td>
        <td class="locationcolumn">New Location</td>
        <td class="roomcolumn"></td>

        <td class="typecolumn">Screening</td>
        <td class="filledtimescolumn">0/0</td>
      </tr>
   </tbody>

  <tfoot>
    <tr class="actionrow">
      <td colspan="2" class="actioncolumn"></td>
      <td colspan="6">With Selected:</td>
    </tr>
    <tr class="actionrow">
                  <td colspan="2" class="actioncolumn">

        <input type="submit" name="button" value="Create New" />
      </td>
                  <td colspan="6">
        <select id="selectactionlist" name="selectaction">
                          <optgroup label="Adjustments">
            <option value="editAppointment">Edit</option>
            <option value="copyAppointment">Copy</option>
            <option value="deleteAppointment">Delete</option>

          </optgroup>
                          <optgroup label="Lists">
                              <option value="viewShowList">Show/No Show List</option>
                              <option value="viewScheduledTimes">Schedule List</option>
          </optgroup>
                          <optgroup label="Hidden">
            <option value="hideAppointment">Hide</option>

            <option value="showAppointment">Show</option>
          </optgroup>
                        </select>
        <input id="selectactionbutton" type="submit" name="button" value="Select" />
      </td>
    </tr>
  </tfoot>         

1 个答案:

答案 0 :(得分:1)

而不是执行以下操作:

    if (foo) {
      $(this).attr("disabled", true);
    } else {
      $(this).attr("disabled", false);
    }

您应该添加和删除disabled属性,因为有时只有disabled属性的存在才能使其被禁用(可能是为什么chrome会禁用它)。试试这个:

if (foo) {
    $(this).attr("disabled", true);
} else {
    $(this).removeAttr("disabled");
}

编辑:试试这个确切的代码

function $recalcSelection($checkbox) {
    $selectActionList.find("option").each(function() {
        $optionLength = $table.find("td.actioncolumn input:checked").length;
        if($optionLength <= 0) {
            $(this).attr("disabled", true);
        } else if($optionLength == 1) {
            $(this).removeAttr("disabled");
        } else {
            if($(this).val() == "editAppointment" ||
                $(this).val() == "copyAppointment" ||
                $(this).val() == "viewShowList" ||
                $(this).val() == "viewScheduledTimes")
            {
                $(this).attr("disabled", true);
            } else {
                $(this).removeAttr("disabled");
            }
        }
    });

    if($selectActionList.find("option:selected").attr('disabled') != "true") {
        $selectActionList.find("option").filter(function () { return $(this).attr("disabled") != null}).eq(0).attr("selected", true);
    }

    if($selectActionList.find("option").filter(function () { return $(this).attr("disabled") != null}).length <= 0) {
        $selectActionButton.attr("disabled", true);
    } else {
        $selectActionButton.removeAttr("disabled");
    }
}​