不同浏览器中的不同Javascript行为

时间:2009-05-29 08:46:47

标签: javascript jquery internet-explorer firefox events

我正在做一个电子商务网站,但是处理Javascript会让我感到害怕。

例如,对于以下页面,http://nordschleife.metaforix.net/118/118/index.php/sony.html

它可以在Google Chrome中使用,但不能在IE或Firefox中使用。例如,单击页面下方产品的向上或向下箭头(例如,第十个产品)将导致页面上升。

我已经使用了event.preventDefault();但它不适用于IE和Firefox。 JS如下:

<script type="text/javascript"> 
jQuery(document).ready(function($){
     $('#upImg_<?php echo $_product->getId();?>').live("click", function() {
                                var textbox = document.getElementById('qty_<?php echo $_product->getId();?>');
                                textbox.value = parseInt(textbox.value)+1;
                                event.preventDefault();
                                });
     $('#downImg_<?php echo $_product->getId();?>').live("click", function() {
                                  var textbox = document.getElementById('qty_<?php echo $_product->getId();?>');
                                  if (textbox.value>1)
                                  textbox.value = parseInt(textbox.value)-1;
                                  event.preventDefault();
                                  });
                                });
</script> 

在此主题PHP generated textbox operation with Javascript

中回答

感谢您的观看。

1 个答案:

答案 0 :(得分:0)

问题是href中的# - 它有一个已定义的行为,你需要覆盖它,最简单的方法是在你的点击处理程序中返回false。

编辑:我知道这是一个骗局 - preventDefault() on an tag