简体   繁体   English

jQuery无法在cshtml上弹出对话框

[英]Jquery not working on cshtml to pop up dialog box

This is the editor for the startdate @Html.EditorFor(model => model.startDate) and I have jquery blow, the code for the query is on the page and when I run the program the calender pop up does not come up, both code are on the dame cshtml page 这是开始日期@Html.EditorFor(model => model.startDate)的编辑器,并且有jquery的打击,查询的代码在页面上,当我运行该程序时,没有弹出日历,代码在dame cshtml页面上

<meta charset="utf-8" />

  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#startDate" ).datepicker();
  });
  </script>

Replace 更换

@Html.EditorFor(model => model.startDate)

with

@Html.EditorFor(model => model.startDate, new { @class="startDate" })

because you have not giveen a class to that field and change your jQuery to 因为您没有给该字段一个类,而是将jQuery更改为

$(function() {
    $( ".startDate" ).datepicker();
  });

so # becomes . 所以#变成了. as we are using a class. 因为我们正在使用一个类。

You need to verify that all your external scripts loaded properly. 您需要验证所有外部脚本是否正确加载。 I suggest you install Fiddler and then watch your requests and see if all of them loaded. 我建议您安装Fiddler,然后观察您的请求,看看是否所有请求都已加载。 If that all is ok then you need to check that the scripts actually load before your call for the datepicker function. 如果一切正常,则需要在调用datepicker函数之前检查脚本是否实际加载。 If you're using MVC 4 and sections feature that would mean that all you javascript code needs to go into the SCRIPTS section which is placed on your view AFTER the calls to load jquery and jquery-ui libraries. 如果您使用的是MVC 4和section功能,则意味着所有JavaScript代码都需要在调用加载jquery和jquery-ui库之后进入放置在视图中的SCRIPTS部分。 Use Goggle Chrome's console to verify that there are no javascript errors. 使用Goggle Chrome的控制台来验证没有javascript错误。

Looking at the code you posted here everything should be working. 查看您在此处发布的代码,一切都应该正常工作。 I've done this millions of times and every time I had a problem it was because I was missing a JQuery library reference or I wasn't loading them in proper order. 我已经完成了数百万次,每次遇到问题都是因为我缺少JQuery库引用,或者没有按正确的顺序加载它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM