jquery一些问题

1、select禁止下拉:

(1)查询的列表为空。

(2)加上属性:$("#selectRows").attr("disabled","disabled");

赋值选择的option:

$("#exfinancingClassifyth").html($("#exfinancingClassify").find("option:selected").text());

判断:

<option value="9" <c:if test="${order.status==9}">selected="selected"</c:if>>已删除</option>

2、a标签去除点击事件

(1)removeAttr('href');

(2)removeAttr('onclick');

3、span赋值内容:$("#spanOne").text(“内容”);

扫描二维码关注公众号,回复: 282739 查看本文章

      修改span弹出文案:$("#spanOne").html(“内容”);  

4、窗口居中:$("#div1").center();隐藏:$("#div1").hide();

5、正则匹配(手机):

var reMobile=/^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))(\d{8})$/;
if(!reMobile.test(mobile)){ }

6、获取根路径

    //获取当前网址,如: http://localhost:8088/test/test.jsp
    var curPath=window.document.location.href;
    //获取主机地址之后的目录,如: test/test.jsp
    var pathName=window.document.location.pathname;
    var pos=curPath.indexOf(pathName);
    //获取主机地址,如: http://localhost:8088
    var localhostPaht=curPath.substring(0,pos);
    //获取带"/"的项目名,如:/cms
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    return(localhostPaht+projectName);

7、h5发送短信倒计时

//初始化
var interValObj;
var count = 60;
var curCount = 0;
....
curCount=count;
$('#smsCode').removeAttr('href');
$("#smsCode").text(curCount+"s后可以重发");
interValObj=window.setInterval(setRemainTime,1000);

function setRemainTime(){
    if(curCount==0){                
    	window.clearInterval(interValObj);
        $("#smsCode").attr("href","javascript:getSmsCode()");
        $("#smsCode").text("重新发送验证码");
    }else{
        curCount--;
        $("#smsCode").text(curCount+"s后可以重发");
    }
}

8、转化循环:

var result = eval('(' + data + ')');
var exfinancingList = result.exfinancingList;
if(exfinancingList.length != 0){
	$('#financingId').html('');
	$.each(exfinancingList,function(index,element){
	var option ="<option value='"+this.id+"'>"+this.title+"</option>";
			$('#financingId').append(option);
	});
}

9、ajax的form表单对象提交:

$("#saveExfinancingJoinForm").serialize()

10、跳转页面对应div:

//其他页面
window.location.href = "<%= request.getContextPath()%>/wf/finance?fc="+ef+"#activityRule";  
//本页面
window.location.hash = "#activityRule";

11、css赋样式:

$(".hint").css({"display":"block"});
 去除样式:
$("div[name='divName']").removeClass(" act");
$("div[name='divName']").removeAttr("name");
$(obj).attr("name","divName");
$("div[name='divName']").addClass(" act");
var money = $("div[name='divName'] input[name='money']").val();
   12、H5到页面底部加载请求,如下一页:
$(window).scroll(function () {
    //已经滚动到上面的页面高度
   var scrollTop = $(this).scrollTop();
    //页面高度
   var scrollHeight = $(document).height();
     //浏览器窗口高度
   var windowHeight = $(this).height();
    //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
    if (scrollTop + windowHeight == scrollHeight) {
    //请求操作
    }
});

猜你喜欢

转载自wwy0612.iteye.com/blog/2377833