您的位置:首页 > 其它

下拉框默认选中当前年、月、日的实现!

2017-05-15 22:11 666 查看
在项目中,经常会用到时间插件,如果实现下拉框的年月日默认选中:

<html>
<script type="text/javascript">
function show(){
var y = document.getElementById("years");
var m = document.getElementById("months");
var d = new Date();
// alert(d.getFullYear());
// alert(d.getMonth());
$("#years").attr("value", d.getFullYear());
$("#months").attr("value", d.getMonth() + 1);
}
</script>

<body onload="show()">
<select id="years">
<c:forEach var="year" begin="2002" end="2032" step="1" >
<option value="${year}" >${year}</option>
</c:forEach>
</select>
<select id="months">
<c:forEach var="month" begin="1" end="12" step="1" >
<option value="${month}">${month}</option>
</c:forEach>
</select>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息