实例一
<pre name="code" class="javascript">$("div ul li div a").click(function(){
$("div ul li div a").each(function(){
$(this).removeClass();
});
$(this).atr("class","here");
})
<div class="box_orange">
<ul class="uls form">
<li><label>规格</label></li>
<div class="pre spec">
<a her="javascript:void(0)" class="here">
32G 黑色
</a>
<a her="javascript:void(0)" class="here">
16G 白色
</a>
</div>
</ul>
</div>
实例二
$("div ul li div a").click(function(){
$("div ul li div a").each(function(){
$(this).removeClass();
});
$(this).atr("class","here");
var skuPrice =$(this).attr("marketPrice");
var skuId = $(this).attr("skuId");
$("#skuPrice").html("¥"+ skuPrice);
$("#marketPrice").html("¥"+ marketPrice);
$.ajax({
url:"${path}/.../getStock.do",
type:"post",
dataType:"text",
data:{
skuId:skuId
},
success:function(responseText){
if(responseText == "no"){
$("#isStock").html("缺 货");
$("#buyNow").hide();
$("#addCart").hide();
}else{
$("#isStock").html("有 货");
$("#buyNow").show();
$("#addCart").show();
}
}
});<pre name="code" class="javascript">$("div ul li div a:first").trigger("click");提交
})
上面的也可以获取样式的方式
$("div ul li div a").each(function(){
var cssHere = $(this).attr("class");
if(cssHere =="here"){
$(this).trigger("click");
}
})
市场价没有要给id 这里没有写
<div class="box_orange">
<ul class="uls form">
<li><label>规格</label></li>
<div class="pre spec">
<a her="javascript:void(0)" class="here">
32G 黑色
</a>
<a her="javascript:void(0)" class="here">
16G 白色
</a>
</div>
</ul>
</div>
<input id="addCart" type="button" value="" class="hand bt138X40b" οnclick="add()" />
<input id="buyNow" type="button" value="" class="hand bt138X40b" οnclick="buy()" />
需要在c层点击需要查询库存 在后台写一个查询方法
@RequestMopping("/getStock.do")
public void getStock(Long skuId,PrintWrite out){
Ebsku ebsku =skuService.selectSkuById(skuId);
String flag="no";
if(ebsku.getStockInventory() > 0){
flag ="yes";
}
out.write(flag);
}