jquery根据datepicker

时间:2018-02-05 10:29:09

标签: jquery

我要做的是创建一个表单,允许用户以两周内工作的小时数的形式输入。

表单有14行,包含要求开始和结束时间的字段。我可以这样做。

我需要做的是在表单中:用户选择一个周末日期,然后根据前14个日期填充14个文本字段。

现在我知道我可以使用以下脚本来执行一个日期,但是如何在没有这么多行代码的情况下一次执行多个字段。

示例:

<script>
$(document).ready(function(){
$( "#datepicker1" ).datepicker({
    onClose: function() {
        var date2 = $('#datepicker1').datepicker('getDate');
        date2.setDate(date2.getDate()+3)
        $( "#datepicker2" ).datepicker("setDate", date2);
    }
});
$( "#datepicker2" ).datepicker();
});

</head>
<body>
<p>Date1: <input type="text" id="datepicker1"></p>
<p>Date2: <input type="text" id="datepicker2"></p> 

1 个答案:

答案 0 :(得分:0)

如果您想设置14个日期,如果每个[error] ErrorHandler - Exception StackTrace: [views.html.modelFormView$.$anonfun$apply$1(modelFormView.template.scala:48), views.html.helper.form$.apply(form.template.scala:36), views.html.modelFormView$.apply(modelFormView.template.scala:41), views.html.modelFormView$.render(modelFormView.template.scala:75), views.html.modelFormView.render(modelFormView.template.scala), controllers.modelController.requestJwt(modelController.java:71), router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$16(Routes.scala:304), play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:134), play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:133), play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:108), play.core.j.JavaAction$$anon$1.call(JavaAction.scala:88), play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:31), play.core.j.JavaAction.$anonfun$apply$8(JavaAction.scala:138), scala.concurrent.Future$.$anonfun$apply$1(Future.scala:655), scala.util.Success.$anonfun$map$1(Try.scala:251), scala.util.Success.map(Try.scala:209), scala.concurrent.Future.$anonfun$map$1(Future.scala:289), scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29), scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29), scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60), scala.concurrent.impl.CallbackRunnable.run(Promise.scala), play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:56), play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:70), play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:48), scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:68), scala.concurrent.impl.Promise$KeptPromise$Kept.onComplete(Promise.scala:368), scala.concurrent.impl.Promise$KeptPromise$Kept.onComplete$(Promise.scala:367), scala.concurrent.impl.Promise$KeptPromise$Successful.onComplete(Promise.scala:375), scala.concurrent.impl.Promise.transform(Promise.scala:29), scala.concurrent.impl.Promise.transform$(Promise.scala:27), scala.concurrent.impl.Promise$KeptPromise$Successful.transform(Promise.scala:375), scala.concurrent.Future.map(Future.scala:289), scala.concurrent.Future.map$(Future.scala:289), scala.concurrent.impl.Promise$KeptPromise$Successful.map(Promise.scala:375), scala.concurrent.Future$.apply(Future.scala:655), play.core.j.JavaAction.apply(JavaAction.scala:138), play.api.mvc.Action.$anonfun$apply$2(Action.scala:96), play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$4(Accumulator.scala:174), scala.util.Try$.apply(Try.scala:209), play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$3(Accumulator.scala:174), scala.Function1.$anonfun$andThen$1(Function1.scala:52), play.api.libs.streams.StrictAccumulator.run(Accumulator.scala:207), play.core.server.AkkaHttpServer.$anonfun$runAction$4(AkkaHttpServer.scala:304), akka.http.scaladsl.util.FastFuture$.strictTransform$1(FastFuture.scala:41), akka.http.scaladsl.util.FastFuture$.$anonfun$transformWith$3(FastFuture.scala:51), scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60), scala.concurrent.impl.CallbackRunnable.run(Promise.scala), akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55), akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91), scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12), scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81), akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91), akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40), akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43), akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260), akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339), akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979), akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)] 具有不同的值,则可以使用each()循环datepicker s。示例如下。

如果所有14个datepicker具有相同的值。您可以使用该类作为选择器来分配值。比如datepicker

$( ".datepicker-to-fill" ).datepicker("setDate",date2);
$(document).ready(function(){
	$( "#datepicker" ).datepicker({
		onClose: function() {
	          $( ".datepicker-to-fill" ).each(function(){
	            var days = parseInt( $(this).data("days") );
	            var date2 = $("#datepicker").datepicker('getDate');
	            date2.setDate( date2.getDate() + days ); 
	            $( this ).datepicker("setDate",date2);
	          });
		}
	});
	$( ".datepicker-to-fill" ).datepicker();
});