来源:https://www.cnblogs.com/xiaoxiao0314/p/7041731.html

1. 设置只能控件只能显示年月:search_date_monthreport为控件id,直接将以下代码复制到js中后替换id为你自己的id即可。

$(function () {
setDateToMonth('search_date_monthreport');
});
function setDateToMonth(id) {
var db1=document.getElementById(id);
var db = $(db1);
db.datebox({
onShowPanel: function () {//显示日趋选择对象后再触发弹出月份层的事件,初始化时没有生成月份层
span.trigger('click'); //触发click事件弹出月份层
//fix 1.3.x不选择日期点击其他地方隐藏在弹出日期框显示日期面板
if (p.find('div.calendar-menu').is(':hidden')) p.find('div.calendar-menu').show();
if (!tds) setTimeout(function () {//延时触发获取月份对象,因为上面的事件触发和对象生成有时间间隔
tds = p.find('div.calendar-menu-month-inner td');
tds.click(function (e) {
e.stopPropagation(); //禁止冒泡执行easyui给月份绑定的事件
var year = /\d{4}/.exec(span.html())[0];//得到年份
var month = parseInt($(this).attr('abbr'), 10); //月份,这里不需要+1
month = month < 10 ? '0' + month : month;
db.datebox('hidePanel')//隐藏日期对象
.datebox('setValue', year + '-' + month); //设置日期的值
});
}, 0);
yearIpt.unbind();//解绑年份输入框中任何事件
},
parser: function (s) {
if (!s) return new Date();
var arr = s.split('-');
return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
},
formatter: function (d) {
return d.getFullYear() + '-' + (d.getMonth() + 1);/*getMonth返回的是0开始的,忘记了。。已修正*/
}
});
var p = db.datebox('panel'), //日期选择对象
tds = false, //日期选择对象中月份
aToday = p.find('a.datebox-current'),
yearIpt = p.find('input.calendar-menu-year'),//年份输入框
//显示月份层的触发控件
span = aToday.length ? p.find('div.calendar-title span') ://1.3.x版本
p.find('span.calendar-text'); //1.4.x版本
if (aToday.length) {//1.3.x版本,取消Today按钮的click事件,重新绑定新事件设置日期框为今天,防止弹出日期选择面板 aToday.unbind('click').click(function () {
var now=new Date();
now = now < 10 ? '0' + now : now;
db.datebox('hidePanel').datebox('setValue', now.getFullYear() + '-' + (now.toString() + 1));
});
}
}; //设置默认时间,默认为当月
$(function (){
setDateToDateBox();
});

2. 附:字符串日期处理:

//格式化日期
function dateFormatHsbc(myDate) {
// alert(myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate());
year = myDate.getFullYear();
month = (myDate.getMonth()+1)>9?(myDate.getMonth()+1):("0"+(myDate.getMonth()+1));
day = myDate.getDate()>9?myDate.getDate():("0"+myDate.getDate());
var str = year+"-"+month+"-"+day;
return str;
}

  //给easyui控件设置值为当月的第一天和最后一天
  var date = $("#search_date_monthreport").datebox('getValue').replace(/-/g,"/");
  var myDate = new Date(Date.parse(date));
  year = myDate.getFullYear();
  month = myDate.getMonth();
  $("#search_sconsigedate").datebox('setValue',dateFormatHsbc(new Date(year,month,1)));
  $("#search_econsigedate").datebox('setValue',dateFormatHsbc(new Date(year,(month+1),0)));

3.附:ajax同步加载,未得到后台结果之前页面显示loading...,使页面无法重复操作

$.ajax({
url:"${path}/path1/method1",
type:'post',
data:{'ckDate':ckDate1},
//dataType:'json',
beforeSend:function(XMLHttpRequest){
$("#dg").datagrid("loading");
},
success:function(data1){
if("success" == data1){
$.messager.alert('My Title','操作成功!','info');
$("#dg").datagrid('reload');
}else{
$.messager.alert('My Title','操作失败!','error');
$("#dg").datagrid('reload');
}
},
error:function(data1){
$.messager.alert('My Title','操作失败!','error');
$("#dg").datagrid('reload');
}
});

easyui-datebox设置只能选择年月,设置当前月的第一天和最后一天的更多相关文章

  1. easyui datebox 扩展 只显示年月

    http://blog.csdn.net/zhaobao110/article/details/47755445 一个日期控件只显示年月是很正常的事情.可是easyui datebox 不支持这种格式 ...

  2. Python 学习笔记:根据输入年月获取该月的第一天和最后一天

    目的: 给定一个时间,比如:2020.02,要求返回所输入月份的第一天及最后一天,比如:('2020.02.01', '2020.02.29') 参考博客:https://blog.csdn.net/ ...

  3. 转 EasyUi日期控件datebox设置,只显示年月,也只能选择年月

    1.引入Jquery和easyui,注低版本的Jquery和easy不能使用,这里使用的Jquery是1.8.2easyui是1.6.1.1.easyui下载地址:http://www.jeasyui ...

  4. easyui时间框只选择年月

    html: <input type="text" id="datetime" > js: <script type="text/ja ...

  5. Easyui控制combotree只能选择叶子节点

    $(function() { $('#tt').combotree({ url: 'getTree.do', onBeforeSelect: function(node) { if (!$(this) ...

  6. elementUI 日期时间选择器 只能选择当前及之后的时间

    日期时间选择器  只能选择当前及之后的时间 <el-date-picker class="input-border-null" prefix-icon="el-ic ...

  7. My97设置开始、结束 时间区间及输入框不能输入只能选择的方法

    时间区间开始: <input type="text" id = "first_time" name="first_time" valu ...

  8. easyui datebox 设置不可编辑

    easyui datebox不允许编辑可以输入 editable="false"<input class="easyui-datebox" editabl ...

  9. easyui datebox时间控件如何只显示年月

    easyui datebox控件,只显示年月,不显示年月日 需要的效果图如下: 具体的js代码: <script> $(function(){ intiMonthBox('costTime ...

随机推荐

  1. rsync技巧

    rsync格式: # 拷贝本地文件.当SRC和DES路径信息都不包含有单个冒号”:”分隔符时就启动这种工作模式.如:rsync -a /data /backup rsync [OPTION]... S ...

  2. gzip压缩解压缩

    压缩/解压缩压缩/解压缩之后的文件名称 必须是gz 解压缩

  3. LeetCode OJ:Gas Station(加油站问题)

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  4. LeetCode OJ:Ugly Number II(丑数II)

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  5. canvas 画布 文字描边

    总结一下,canvas 画布 文字描边的2种方法以及其不同的视觉效果: 效果图: 具体代码: <canvas id="canvas" width="800" ...

  6. Linux:减号(-)详解

    减号(-) 代表标准输出/标准输入, 视命令而定. “-”代替stdin和stdout的用法 为应用程序指定参数 ps -aux tar -zxf test.tar 一个减号和两个减号 一个减号后面跟 ...

  7. chrome浏览器使用记录

    出现错误 net::ERR_BLOCKED_BY_CLIENT 出现这个错误一般是因为chrome安装了adblocker等这样的插件,这些插件会把路径及文件名中包含广告字样的文字禁止掉,比如:adv ...

  8. Luogu 4149 Race

    Luogu 4149 Race 用点分治解决. 点分治在计算路径贡献时,为了不统计在一颗子树中的路径,解决方法一种是容斥,但在这种求最值问题中不便用容斥来撤销. 另一种则是,处理一颗子树时,只考虑前面 ...

  9. POJ1201 Intervals【差分约束系统】

    Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...

  10. windows中查看端口被什么应用程序占用并删除

    windows中查看端口的命令是netstat,具体用法如下: 查看端口信息时可以使用如下命令: netstat -ano 运行结果如下: 当前我的本地13067端口被占用,使用命令如下: c:\&g ...