Javascript 如何仅添加5个动态文本框以及如何仅在datepicker中显示当前周
我有一个要求生成动态文本框和datepicker在javascript中使用正确生成的jsp动态文本框,但现在我想限制用户添加多达5个动态文本框,也在datepicker中,我只想显示当前周而不是整个月,我对这两个都进行了编码,但没有任何效果不知道为什么添加屏幕截图以获得更多了解还有日期选择器Javascript 如何仅添加5个动态文本框以及如何仅在datepicker中显示当前周,javascript,jquery,Javascript,Jquery,我有一个要求生成动态文本框和datepicker在javascript中使用正确生成的jsp动态文本框,但现在我想限制用户添加多达5个动态文本框,也在datepicker中,我只想显示当前周而不是整个月,我对这两个都进行了编码,但没有任何效果不知道为什么添加屏幕截图以获得更多了解还有日期选择器 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <link re
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"/>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
//script for allow only 5
$(function () {
$("#date_ex").datepicker({
firstDay: 0,
beforeShowDay: function (date) {
//var sunday = new Date("June 2, 2013 00:00:00");
var sunday = new Date();
sunday.setHours(0,0,0,0);
//alert(sunday.getDay() + ' : ' + sunday.getDate() + ' : ' + (sunday.getDay() || 0) + ' : ' + sunday.getTime());
sunday.setDate(sunday.getDate() - (sunday.getDay() || 0));
var saturday = new Date(sunday.getTime());
saturday.setDate(sunday.getDate() + 5);
return [(date >= sunday && date <= saturday), ''];
}
});
$("#date_ex").datepicker("option", "dateFormat", "dd/mm/yy");
});
<script>
var index = 0;
var name='<%=test%>';
function getinput()
{
index ++;
var singleRecord = "";
singleRecord += "Project_name : <input type='text' name='txt_project_name"+index+"'>";
singleRecord += "Project/Task : <input type='text' name='txt_Header"+index+"'>";
singleRecord += "Department : <input type='text' name='txt_Department"+index+"'>";
singleRecord += "Description : <input type='text' name='txt_description"+index+"'>";
singleRecord += "Date : <input type='text' id='date_ex" + index+ "' name='txt_date"+index+"'><br/>";
singleRecord += "<hr/>";
$("#inputs").append(singleRecord);
$( "#date_ex" +index).datepicker();
$("#count").val(index);
//this is for generate only 5 textbox
if(index.length<6)
{
alert('error');
}
}
</script>
</head>
<body background="images\blue_background.jpg">
<form action="EmployeeVendorValidation.jsp" method="post" autocomplete="off">
<br><br><br><br>
<input type="hidden" name="count" id="count"/>
<input type="hidden" name="date_ex" id="date_ex"/>
<div id="inputs">
</div>
<button type="button" onclick="getinput()" class="button button5">Add</button>
<button type="button" onclick="removeElement()" class="button button5">Remove</button>
<button type="submit" class="button button2">Submit</button>
</form>
</body>
防止添加超过5个
function getinput()
{
if($('[name*="txt_project_name"]').length >= 5) return false;
//your code here
}
仅显示当前周
var week = ['0','1','2','3','4','5','6'];
var date = new Date(), curDay = date.getDay();
var minDate = curDay;
var maxDate =week.length - week.indexOf(String(curDay))-1;
console.log(minDate,maxDate)
$( "#date_ex" +index).datepicker({
maxDate: "+"+maxDate+"d",
minDate: "-"+minDate+"d"
});
完整的小提琴链接:谢谢@pandian\u snkl其工作正常,非常感谢: