Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将日期选择器添加到文本框_Javascript_Jquery_Twitter Bootstrap_Razor_Datepicker - Fatal编程技术网

Javascript 将日期选择器添加到文本框

Javascript 将日期选择器添加到文本框,javascript,jquery,twitter-bootstrap,razor,datepicker,Javascript,Jquery,Twitter Bootstrap,Razor,Datepicker,我需要将两个日期作为筛选器传递给我的控制器。我在视图中有两个文本框,需要在单击时弹出日期选择器 我在网上尝试了许多变体。我尝试过使用引导数据采集器和JqueryUI。但两者似乎都没有给我任何输出 <th> @*<input class="date-picker" /> <input type="text" name="from" class="date-picker"/>*@ <p> From : &l

我需要将两个日期作为筛选器传递给我的控制器。我在视图中有两个文本框,需要在单击时弹出日期选择器

我在网上尝试了许多变体。我尝试过使用引导数据采集器和JqueryUI。但两者似乎都没有给我任何输出

<th>
     @*<input class="date-picker" />
     <input type="text"  name="from" class="date-picker"/>*@
     <p>
       From : <input type="text" name="from"  id="from"/>
       <br />
       To : <input type="text" name="to" id="to"/>
     </p>
</th>
脚本文件的顺序是否有问题


我的智能感知没有显示datepicker而是显示datetimepicker。。但我试着用这两种方法都没有效果。使用razor。

在本例中,我将datepicker添加到您的页面:

我仍在试图理解你为什么要使用这些javascript代码,你只需要:

$(document).ready(function () {
    $('#from, #to').datepicker();
});

因此,我发现问题在于脚本文件的顺序。帮我找到了解决办法。我按照以下顺序在html文件的头部添加了脚本文件

@Styles.Render("~/Content/themes/base/css", "~/Content/css", "~/Content/datepicker3.css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/Content/bootstrap-datepicker.js")
在bundle配置中,我添加了以下内容。添加完整的bundle文件是为了避免将来的读者混淆

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
            "~/Scripts/jquery-ui-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css",
                  "~/Content/Custom.css"));
        bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
      "~/Content/themes/base/core.css",
      "~/Content/themes/base/resizable.css",
      "~/Content/themes/base/selectable.css",
      "~/Content/themes/base/accordion.css",
      "~/Content/themes/base/autocomplete.css",
      "~/Content/themes/base/button.css",
      "~/Content/themes/base/.dialog.css",
      "~/Content/themes/base/slider.css",
      "~/Content/themes/base/tabs.css",
      "~/Content/themes/base/datepicker.css",
      "~/Content/themes/base/progressbar.css",
      "~/Content/themes/base/theme.css")); 

    }

但是我没有改变布局。而且他们知道如何称呼日期选择器

除了HTML或CSS之外,您是否还专门使用其他东西
@Scripts.Render()
是Razor吗?是的,我正在使用Razor。我正在开发一个MVC5应用程序。在我的问题中添加了详细信息,最好对其进行标记,以便Razor用户能够看到这一点。您能告诉我控制台中发生了什么吗?有错误吗?我尝试在控制台中为脚本设置断点。它被点击了,但是我找不到在点击按钮上发生的任何事情。在添加我的所有代码之前,我也尝试过单独使用你的代码。我在一些教程中找到了它。我打赌问题在于如何在视图中添加javascript。是否确实要将其添加到布局页面的“脚本”部分?我认为@stibay也是如此,否则此代码应该可以正常工作。@SerhanKarakaya:我不确定应该在何处添加脚本以及应该遵循的顺序..:(正如我已经提到的,我的intellisense没有显示datepicker,而是显示datetimepicker。我已经更改了脚本文件的顺序,它成功了。
@Styles.Render("~/Content/themes/base/css", "~/Content/css", "~/Content/datepicker3.css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/Content/bootstrap-datepicker.js")
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
            "~/Scripts/jquery-ui-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css",
                  "~/Content/Custom.css"));
        bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
      "~/Content/themes/base/core.css",
      "~/Content/themes/base/resizable.css",
      "~/Content/themes/base/selectable.css",
      "~/Content/themes/base/accordion.css",
      "~/Content/themes/base/autocomplete.css",
      "~/Content/themes/base/button.css",
      "~/Content/themes/base/.dialog.css",
      "~/Content/themes/base/slider.css",
      "~/Content/themes/base/tabs.css",
      "~/Content/themes/base/datepicker.css",
      "~/Content/themes/base/progressbar.css",
      "~/Content/themes/base/theme.css")); 

    }