我正在使用以下代码,它在我见过的所有浏览器中都工作正常,IE9 很好,但后来我来到 IE8,它根本不起作用..仅供引用 # cal_popup_table
元素动态添加到页面..
$("#cal_popup_table tbody tr td a").live('click', function() {
$('.datepick-cmd-today').text(from_month + ' ' + from_year);
var test = from_yeartest + '-' + from_monthtest + '-' + from_daytest;
var test_new = test.split("-");
var today = test_new[0] + '-' + test_new[1] + '-' + test_new[2];
$("#arrival").val(today);
});
任何人都可以解释一下为什么它可能无法正常工作吗?函数内的代码并不重要,因为简单的 alert()
也不起作用......点击事件只是根本不会开火
更新 - 这是插入到页面中的代码(删除了一些内容等)
<div id="cal_popup" class="datepick-popup" style="position: absolute; left: 901px; top: 219px; ">
<div class="datepick" style="width: 195px; ">
<div class="datepick-nav">
<a href="javascript:void(0)" title="Show the previous month" class="datepick-cmd datepick-cmd-prev datepick-disabled"><</a>
<a href="javascript:void(0)" title="Show today's month" class="datepick-cmd datepick-cmd-today ">December 2012</a>
<a href="javascript:void(0)" title="Show the next month" class="datepick-cmd datepick-cmd-next ">></a>
</div>
<div class="datepick-month-row">
<div class="datepick-month">
<table id="cal_popup_table">
<tbody>
<tr>
<td>
<a href="javascript:void(0)" class="datepicker_link dp1354708800000 datepick-today datepick-highlight" title="Select Wednesday, Dec 5, 2012">5</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
最佳答案
尝试删除 tbody
:
$("#cal_popup_table tr td a").live('click', function() {
某些浏览器会添加 <tbody>
自动生成的表,但 IE 8 没有。
这就是 JS 在 IE 8 中无法执行你的代码的原因。
关于javascript - jquery 实时点击事件在 IE8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13720673/