<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
$("#add").click(function(){
var sum = $("#sum").val()
var result = Number(sum)+1
$("#sum").val(result)
})
$("#down").click(function(){
var sum = $("#sum").val()
var result = Number(sum)-1
$("#sum").val(result)
})
})
</script>
</head>
<body>
<input id='sum' value='0'>
<p id='add'>添加</p>
<p id='down'>减少</p>
</body>
</html>
跟这个类似
addRemoveItem('add','shangpindizhi') 这个事件似乎在添加之前并没有判断maxid等于几,而是在添加以后判断的。你应该在document.createElement之前判断是否等于6,等于6就不执行<script type="text/javascript">
var maxid = 2
function addRemoveItem(act,target){
if ((!act || act == 'add') &&target){
var $shangpindizhi = typeof(target) != 'object' ? document.getElementById(target) : target
if (!$shangpindizhi) return
if(maxid<="6"){
var obj = document.createElement('<div style="border-bottom:1px #CCC dotted">')
obj.innerHTML = "商品地址"+maxid+":<INPUT class=txt id=ProUrl"+maxid+" style='WIDTH: 215px' name=ProUrl"+maxid+" value=http://>" + '<input type="button" value="-" onclick="javas'+'cript:addRemoveItem(\'del\',this.parentNode)" style="font-size:12px"/></div>'
$shangpindizhi.appendChild(obj)
obj = $shangpindizhi = null
maxid++
}else{
alert('购物车商品超过6个无效!')
return false
}
} else if (act == 'del' &&target){
if (typeof(target) != 'object') return
target.parentNode.removeChild(target)
maxid--
}
}
</script>
<script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>在你的script的前面先引用这个
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)