日期选择器和 Laravel 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33764286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Datepicker and Laravel 5
提问by Ricki Moore
Im trying to implement the datepicker.js with my laravel project. I downloaded the css/js and placed them in my assets and called them in the app template. Then I used my Js to call the date-picker on my form using the correct id but nothing is coming up and no errors either. Here is what I have:
我试图用我的 Laravel 项目实现 datepicker.js。我下载了 css/js 并将它们放在我的资产中并在应用程序模板中调用它们。然后我使用我的 Js 使用正确的 id 调用表单上的日期选择器,但没有出现任何错误,也没有错误。这是我所拥有的:
App:
应用程序:
<!doctype html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/assets/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/assets/css/gin_add.css">
<title>Elephant Gin</title>
</head>
<body>
@yield('main')
<script src="/assets/js/jquery-2.1.1.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/bootstrap-datepicker.min.js"></script>
<script src="/assets/js/gin_add.js"></script>
</body>
</html>
Form-Field:
表单字段:
{!! Form::text('date', null, array('type' => 'text', 'class' => 'form-control datepicker','placeholder' => 'Pick the date this task should be completed', 'id' => 'calendar')) !!}
Javascript:
Javascript:
$('#calender').datepicker({
format: "dd/mm/yyyy",
forceParse: false
});
回答by IlGala
I was looking around google about Laravel and bootstrap-datepicker and found this link. One of the answer was:
我在谷歌上搜索关于 Laravel 和 bootstrap-datepicker 的内容,找到了这个链接。答案之一是:
Just Curious.
Did you have jQuery installed before your bootstrap-datepicker.js? Looks like jQuery is a dependency of this bootstrap-datepicker.js
See: http://bootstrap-datepicker.readthedocs.org/en/release/
只是好奇。
你在 bootstrap-datepicker.js 之前安装了 jQuery 吗?看起来 jQuery 是这个 bootstrap-datepicker.js 的依赖项
请参阅:http: //bootstrap-datepicker.readthedocs.org/en/release/
But it doesn't seem to be your case since you wrote
但自从你写了这似乎不是你的情况
<script src="/assets/js/jquery-2.1.1.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/bootstrap-datepicker.min.js"></script>
<script src="/assets/js/gin_add.js"></script>
but, in my opinion, it may still be a conflict with an existing JQuery datepicker... So as you can read from the official documentationyou can set your datepicker in No conflict mode
by adding
但是,在我看来,它可能仍然与现有的 JQuery 日期选择器存在冲突......因此,您可以从官方文档中阅读, 您可以No conflict mode
通过添加来设置您的日期选择器
var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
$.fn.bootstrapDP = datepicker; // give $().bootstrapDP the bootstrap-datepicker functionality