<c:forEach items="${sessionScope.cart.cartItem}" var="cartI">
<div class="cart-con-info">
<div class="info-top">
</div>
<div class="info-mid">
<input type="checkbox" value="" name="hobby" class="mid-ipt f-l"></input>
<div class="mid-tu f-l">
<a href="#"><img src="${pageContext.request.contextPath}/images/dai1.gif" /></a>
</div>
<div class="mid-font f-l">
<a href="#">登高阁紫菜肉松鸡蛋卷 海苔蛋卷 糕点<br />江西特产小吃 休闲办公零食</a>
<span>满赠</span>
</div>
<div class="mid-guige f-l">
<p>颜色:蓝色</p>
<p>尺码:XL</p>
<a href="JavaScript:;" class="xg" xg="xg1">修改</a>
<div class="guige-xiugai" xg-g="xg1">
<div class="xg-left f-l">
<dl>
<dt>颜 色</dt>
<dd>
<a href="JavaScript:;" class="current">黑色</a>
<a href="JavaScript:;">白色</a>
</dd>
<div style="clear:both;"></div>
</dl>
<dl>
<dt>尺 码</dt>
<dd>
<a href="JavaScript:;" class="current">M</a>
<a href="JavaScript:;">L</a>
<a href="JavaScript:;">XL</a>
</dd>
<div style="clear:both;"></div>
</dl>
<a href="JavaScript:;" class="qd">确定</a>
<a href="JavaScript:;" class="qx" qx="xg1">取消</a>
</div>
<div class="xg-right f-l">
<a href="#"><img src="${pageContext.request.contextPath}/images/dai2.gif" /></a>
</div>
<div style="clear:both;"></div>
</div>
</div>
<div class="mid-sl f-l">
<a href="JavaScript:;" class="sl-left">-</a>
<input type="text" value="${cartI.count}" />
<a href="JavaScript:;" class="sl-right" id="${cartI.productExt.pid}" name="plus">+</a>
</div>
<p class="mid-dj f-l">¥ <span>${cartI.price}</span></p>
<p class="mid-je f-l">¥ <span>${cartI.sum}</span></p>
<div class="mid-chaozuo f-l">
<a href="#">移入收藏夹</a>
<a href="#">删除</a>
</div>
<div style="clear:both;"></div>
</div>
</div>
</c:forEach>
当上方元素是遍历出来的时候,要定位 <a href="JavaScript:;" class="sl-right" id="${cartI.productExt.pid}" name="plus">+</a>标签时,只需要通过class里的.sl-right属性触发事件即可,如下:
$(".mid-sl .sl-right").click(function(event) {
var pid = $(this).attr("id");
var vl = $(this).siblings("input").val();
$.ajax({
url : "../cart/updatePro.do",
type : 'post',
data :{
pid : pid,
count : vl
},
success : function (data) {
}
});
});
此时已经定位到多行数据中的某一行,要获取此行的数据只需要var pid = $(this).attr("属性名");即可获取属性中的值。