1. 遍历name相同的控件值
//jsp页面
<input type="hidden" name="presId" value="1">
<input type="hidden" name="presId" value="2">
<input type="hidden" name="presId" value="3">
//js presIds为所有ID
var presIds = "";
//if ($("input:checked[name='presId']").length > 0) {
$($("input[name='presId']")).each(function() {
presIds += this.value + ",";
});
//}
2. 去空格
var products = $.trim($("#products").val());
if(products.length==0){
$("#subBtn").attr("disabled",false);
}
3. 取name相同的数组长度
<span name='spanTName' value='0001' />
<span name='spanTName' value='0002' />
<span name='spanTName' value='0003' />
var len = $("span[name='spanTName']").length;
------------------------------------------------------------
<input type='hidden' id='picLogo1' name='imgUrl' value='1'/>
<input type='hidden' id='picLogo2' name='imgUrl' value='2'/>
<input type='hidden' id='picLogo3' name='imgUrl' value='3'/>
var len = $("input[name='imgUrl']").length;
4. JQuery下锚点的平滑跳转
JS: $("html,body").animate({scrollTop:$("#commentTitleId").offset().top},800);
Html:<a name="commentTitleId" id="commentTitleId"></a>
jquery常用方法
最新推荐文章于 2024-11-08 16:09:18 发布