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;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。