IE(所有版本)跟随href而不是执行JS

时间:2012-09-25 13:22:50

标签: javascript internet-explorer href

我在所有版本的浏览器中遇到IE(谁没有)的问题。它在其他所有浏览器中都能正常运行

<a href="<?php echo base_url() ?>pages/delete_page/<?php echo $row->id; ?>" class="delete" data-uid="<?php echo $row->id; ?>">
    <i class="icon-cancel"></i><span class="delete_tooltip">delete page</span>
</a>

这是我的<a>标记,非常简单。

基本上IE跟随href并且根本不执行JS。如果我从href中删除链接,它只是将其发送回主页。

我正在使用插件来加载模式框,就像我说的,在每个浏览器中一切正常。

$('.delete').click(function(e) {    
  console.log($('#modal-'+$(this).data('uid')));    // Button which will activate our modal
  $('#modal-'+$(this).data('uid')).reveal({                // The item which will be opened with reveal
      animation: 'fadeAndPop',              // fade, fadeAndPop, none
      animationspeed: 400,            // how fast animtions are
      closeonbackgroundclick: false,   // if you click background will modal close?
      dismissmodalclass: 'modal_cancel'      // the class of a button or element that will close an open modal
  });
  return false;
});

这就是将插件调用到该链接的JS。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

这可能是个有趣的......

console.log($('#modal-'+$(this).data('uid')));将在IE中导致异常,因此永远不会返回false,导致href执行其默认操作。

编辑: 可能在这里引起了一些混乱。在IE中,它会导致异常,因为consoleundefined

答案 1 :(得分:0)

$('.delete').click(function(e) {
  e.preventDefault();
  ...

在处理程序中使用preventDefault()

http://api.jquery.com/event.preventDefault/以供参考