【发布时间】:2009-05-29 08:46:47
【问题描述】:
我正在做一个电子商务网站,但处理 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
感谢观看。
【问题讨论】:
-
如果您使用的是 jQuery,那么为什么要 var textbox = document.getElementById('qty_getId();?> ?只是为了 $('#getId();?>'); 然后 textbox.value>1 变成 textbox.val() > 1
标签: javascript jquery internet-explorer firefox events