日期:2014-05-16  浏览次数:20345 次

求指教!淘宝购买数量的方法为什么不能用在所有的对象上面?
我的页面中需要多个数量增加对象,如图

我写了如下的javascript方法,
<script type="text/javascript">
function addNum()
{
var num = document.getElementById("buyNum").value;
if(num==""){num = 0;}else num = parseInt(num);
document.getElementById("buyNum").value = num + 1;}
function reduceNum()
{
var num = document.getElementById("buyNum").value;
var able=document.getElementById("reduce").visible;
if(num=="0"){able.visible = false;}else num = parseInt(num);
document.getElementById("buyNum").value = num - 1;
}
</script>
问题是:这个方法只对第一个数量对象有效,不是对所有的对象有效???不能所有的数量对象都实现增加减少功能???求指教,急急急。。。。

------解决方案--------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
<script type="text/javascript">
/*function addNum(){
var num = document.getElementById("buyNum").value;
if(num==""){
num = 0;
}else{
num = parseInt(num);
}
document.getElementById("buyNum").value = num + 1;
}
function reduceNum(){
var num = document.getElementById("buyNum").value;
var able=document.getElementById("reduce").visible;
if(num=="0"){
able.visible = false;
}else{
num = parseInt(num);
}
document.getElementById("buyNum").value = num - 1;
}*/
jQuery(function($){
$('span[rel=reduce]').click(function(){
//当前值
var currentInput=$(this).parents('div').find('input[rel=buyNum]');
if(currentInput.val() == "0"){
 $(this).attr('disabled','true');
}else{