2011-12-24 70 views
1

这适用于FF和Chrome,但点击在IE中没有任何操作。Internet Explorer无法识别脚本标记中的jquery

这是相关的javascript,在创建条目后调用。

<script> 
$(".reserveAPickupAppointmentRoommateAppointment").click (function() { 
    if ($(this).hasClass("confirm")) { 
    } 
    else { 
     $("img").remove(".confirmAppointment"); 
     $(".reserveAPickupAppointmentRoommateAppointment").removeClass("confirm"); 
     $(this).addClass("confirm"); 
     $(this).append("<img src=images/confirmAppointment.png class=confirmAppointment id=roommateAppointment>"); 
     var entry = this; 
     $(".confirmAppointment").click (function() { 
      $(".confirmAppointment").unbind("click"); 
      var location = $(".reserveAPickupAppointmentLocation", entry).text(); 

      alert (location); 
     }); 

    } 
    }); 
</script> 

培训相关的PHP/HTML ... jQuery的immedeatly遵循这个脚本标签

echo '<table>'; 
while ($row = mysql_fetch_array($result)) { 

echo 
'<tbody class = "reserveAPickupAppointmentRoommateAppointment"> 
    <tr> 
      <td>' 
       .$row["name"]. 
      '</td> 
      <td> 
       <span class = "reserveAPickupAppointmentlocation">' 
        .$row["location"]. 
       '</span> 
      </td> 
      <td> 
       <span class = "reserveAPickupAppointmentSublocation">' 
        .$row["subLocation"]. 
       '</span> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <span class = "reserveAPickupAppointmentStartTime">' 
       .$row["startTime"]. 
      '</span> - 
      <span class = "reserveAPickupAppointmentEndTime">' 
      .$row["endTime"]. 
       '</span> 
      </td> 
      <td> 
       <span class = "reserveAPickupAppointmentDate">' 
       .$row["date"]. 
       '</span> 
      </td> 
     </tr> 
    </tbody>'; 
} 

echo '</table> 

使用警报

$(".reserveAPickupAppointmentRoommateAppointment").click (function() { 
    if ($(this).hasClass("confirm")) { 
    } 
    else { 
     $("img").remove(".confirmAppointment"); 
     alert ("TEST1"); 
     $(".reserveAPickupAppointmentRoommateAppointment").removeClass("confirm"); 
     alert ("TEST2"); 
     $(this).addClass("confirm"); 
     alert ("TEST3"); 
     $(this).append("<img src=\'images/confirmAppointment.png\' class=\'confirmAppointment\' id=\'roommateAppointment\'>"); 
     alert ("TEST4"); 
     var entry = this; 
     alert ("TEST5"); 
     $(".confirmAppointment").click (function() { 
      $(".confirmAppointment").unbind("click"); 
      var location = $(".reserveAPickupAppointmentLocation", entry).text(); 

      alert (location); 
     }); 

    } 
    }); 
+0

标记? [SSCCE](http://sscce.org)? A [jsFiddle](http://jsfiddle.net),也许? _好吧,如果你不打算付出努力,那么我也不会。 – 2011-12-24 05:16:46

+0

对不起,我今天刚刚学习了jsFiddle,现在我会尝试...并且我承诺我已经付出了努力在这。 – radleybobins 2011-12-24 05:17:48

+0

什么版本的IE? – 2011-12-24 05:17:55

回答

2

您试图将图像追加到TBODY 。我认为这将是一个无效的HTML,因此不适用于IE。你将不得不将图像追加到td而不是tbody。请尝试以下代码:

<script type="text/javascript"> 
$(".reserveAPickupAppointmentRoommateAppointment").click (function() { 
    if ($(this).hasClass("confirm")) { 
    } 
    else { 
     $("img").remove(".confirmAppointment"); 
     $(".reserveAPickupAppointmentRoommateAppointment").removeClass("confirm"); 
     $(this).addClass("confirm"); 
     $(this).find('.confirm_button').append("<img src=\'images/confirmAppointment.png\' class=\'confirmAppointment\' id=\'roommateAppointment\'>"); 
     var entry = this; 
     $(".confirmAppointment").click (function() { 
      $(".confirmAppointment").unbind("click"); 
      var location = $(".reserveAPickupAppointmentLocation", entry).text(); 

      alert (location); 
     }); 

    } 
    }); 
</script> 

echo '<table>'; 
while ($row = mysql_fetch_array($result)) { 

echo 
'<tbody class = "reserveAPickupAppointmentRoommateAppointment"> 
    <tr> 
      <td>' 
       .$row["name"]. 
      '</td> 
      <td> 
       <span class = "reserveAPickupAppointmentlocation">' 
        .$row["location"]. 
       '</span> 
      </td> 
      <td> 
       <span class = "reserveAPickupAppointmentSublocation">' 
        .$row["subLocation"]. 
       '</span> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <span class = "reserveAPickupAppointmentStartTime">' 
       .$row["startTime"]. 
      '</span> - 
      <span class = "reserveAPickupAppointmentEndTime">' 
      .$row["endTime"]. 
       '</span> 
      </td> 
      <td> 
       <span class = "reserveAPickupAppointmentDate">' 
       .$row["date"]. 
       '</span> 
      </td> 
     </tr> 
<tr><td class="confirm_button"></td></tr> 
    </tbody>'; 
} 

echo '</table>'; 
+0

再次感谢您的帮助! – radleybobins 2011-12-24 06:02:39

1

JQUERY IE可能是有关脚本标签有点挑剔。尝试:

<script type="text/javascript"> 
+0

很好的建议,但这似乎没有什么区别。 – radleybobins 2011-12-24 05:21:24

+0

似乎不是问题。 – 2011-12-24 05:21:31

1

我不得不面对这类问题很多次, 可能的解决方案,

- > ViewSource

  • 检查,如果有任何错误的HTML语法,在我的情况,我搞砸了 与结束标签,例如检查您的标记或其他语法检查
  • 最好的是检查与html validator,http://validator.w3.org/,你会得到更多的想法。
  • 在上面的代码
  • ,我想你需要把那些$(document).ready

,如果你没有得到解决,让我有你的viewsource,

+0

这是一个很好的工具,谢谢你的提示。不适用于php,但绝对有用。 – radleybobins 2011-12-24 05:53:37

相关问题