前端JS、JQuery、CSS常用操作

input 标签

以id进行操作
js:
    document.getElementById("txt").style.borderStyle="solid";//边框样式
    document.getElementById("txt").style.borderColor="#ff0000";//边框颜色
    document.getElementById("txt").style.borderWidth="1px";//边框宽度
jquery:
    $("#username").css("border-style","solid");//边框样式
    $("#username").css("border-color","rgb(218, 38, 38)");//边框样式
    $("#username").css("border-width","2px");//边框样式

select 标签

去除重复数据

入参为select标签ID
function del(obj) {
    var items = document.getElementById(obj);
    var sobj = (function() {
        var _sobj = {};
        for (var i = 0; i < items.options.length; i++) {
            _sobj[items.options[i].text] = 1;
        }
        return _sobj;
    })();
    items.options.length = 0;
    var _cx = 0;
    for (var i in sobj) {
        items.options[_cx] = new Option(i, i);
        _cx += 1;
    }
}

设置认值

<select id="sel" >
      <option value="aa" > 123</option>
      <option value="bb" > 321</option>
 </select>
 
第一种设置值:
$(function(){
    $("#sel").attr("aa","<%=123 %>")
});

第二种设置值得方式:是将select中的任何一个 option 来设为认值
$(function(){
    $("#sel option[value='bb'] ").attr("selected",true)
});

发送请求

location.href

self.location.href;//当前页面打开URL页面
window.location.href;//当前页面打开URL页面
this.location.href;//当前页面打开URL页面
location.href;// 当前页面打开URL页面
parent.location.href;//在父页面打开新页面
top.location.href;//在顶层页面打开新页面

window.location.href='/query/shop/api/list.do?name='+name;

ajax

$.ajax({    
   type: 'POST',    
    dataType : 'json',
    data:{'nae':'test'},//传递的参数
    url: '/query/shop/api/list.do',//controller  
    success:function(data){ 
		// 成功
    },
    error:function(data){
        // 失败
    }
});

日期对比

判断日期跨度

// 判断时间段长度单位(天)
function checkTime(){
	var kprqq = $("#search_kprqq").val();
	var kprqz = $("#search_kprqz").val();
	if(kprqq!=null&&kprqz!=null){
        var s1 = new Date(kprqq.replace(/-/g, "/"));
        var s2 = new Date(kprqz.replace(/-/g, "/"));
        var days = s2.getTime() - s1.getTime();
        var time = parseInt(days / (1000 * 60 * 60 * 24));
        if(time>31){
            alert("选取时间段超过31天! 请重新选择!!!");
            return false;
        }
    }
    return true;
}

校验是否为空

function checkTime(){
     var begintime = document.getElementById('startTime').value;
     var endtime = document.getElementById('endTime').value;
     if(!endtime){
         return true;
     }

     var time1 = new Date(begintime).getTime();
     var time2 = new Date(endtime).getTime();
     if(begintime==''){
         alert("开始时间不能为空");
         return false;
     }
     if(endtime==''){
         alert("结束时间不能为空");
         return false;
     }
     if(time1 > time2){
         alert("开始时间不能大于结束时间");
         return false;
     }
}

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...