2012-11-05 2 views
2

이제는 이전에 요청되었지만 Jquery 대화 상자가 작동하지 않는 것 같습니다.MVC에서 Jquery 대화 상자가 작동하지 않습니다.

JQUERY 웹 사이트에서 얻은 쉬운 예가 있지만 대화 상자가 나타나지 않습니다.

내 _Layout.cshtml 페이지

<!DOCTYPE html> 
    <html lang="en"> 
     <head> 
      <meta charset="utf-8" /> 
      <title>@ViewBag.Title - My ASP.NET MVC Application</title> 
      <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
      <meta name="viewport" content="width=device-width" /> 
      <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script> 
      <script src="@Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script> 
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" /> 
      @Styles.Render("~/Content/css") 
      @Scripts.Render("~/bundles/modernizr") 
     </head> 
     <body> 
      <header> 
       <div class="content-wrapper"> 
        <div class="float-left"> 
         <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p> 
        </div> 
        <div class="float-right"> 
         <section id="login"> 
          @Html.Partial("_LoginPartial") 
         </section> 
         <nav> 
          <ul id="menu"> 
           <li>@Html.ActionLink("Home", "Index", "Home")</li> 
           <li>@Html.ActionLink("About", "About", "Home")</li> 
           <li>@Html.ActionLink("Contact", "Contact", "Home")</li> 
          </ul> 
         </nav> 
        </div> 
       </div> 
      </header> 
      <div id="body"> 
       @RenderSection("featured", required: false) 
       <section class="content-wrapper main-content clear-fix"> 
        @RenderBody() 
       </section> 
      </div> 
      <footer> 
       <div class="content-wrapper"> 
        <div class="float-left"> 
         <p>&copy; @DateTime.Now.Year - My ASP.NET MVC Application</p> 
        </div> 
       </div> 
      </footer> 

      @Scripts.Render("~/bundles/jquery") 
      @RenderSection("scripts", required: false) 
     </body> 
    </html> 

내 Index.cshtml 페이지

<div id="dialog" title="Basic dialog"> 
     <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p> 
    </div> 

<script type="text/javascript"> 
    $(function() { 
     alert("HELLO"); 
    }); 
</script> 

    <script type="text/javascript"> 
     $(function() { 
      $("#dialog").dialog(); 
     }); 
    </script> 

경고가 나타나고 있지만 대화 상자가 아니라 어떤 생각 이유는 무엇입니까?

편집 : 편집을했는데 지금 이걸 가지고 있습니다. 나는 그것이 3 경고를 표시합니다 대화 스크립트 위의 HELLO3 스크립트를 넣을 경우 .. 나는 세 가지 경고가있을 때

<div id="dialog" title="Basic dialog"> 
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p> 
</div> 

<script type="text/javascript"> 
    $(function() { 
     alert("HELLO"); 
    }); 
</script> 

<script type="text/javascript"> 
    $(function() { 
     alert("HELLO2"); 
    }); 
</script> 

<script type="text/javascript"> 
    $(function() { 
     $("#dialog").dialog(); 
    }); 
</script> 

<script type="text/javascript"> 
    $(function() { 
     alert("HELLO3"); 
    }); 
</script> 

는 지금, 그것은 HELLO 및 HELLO2을 알려드립니다하지만 HELLO3을하지 않았다. 어떤 아이디어가 진행되고 있습니까?

답변

1

그냥 그 자체로 찾아 작품 : http://jsfiddle.net/Dy2Xw/

가 제대로로드되어 있는지 확인하는 스크립트를 확인합니다. 또한 jquery base js를 두 번로드하는 것으로 보입니다.

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script> 

<script src="http://code.jquery.com/jquery-1.8.2.js "></script> 

또한 두 개의 CSS 파일이 - 확실하지 왜 당신이 그 모두를 필요 :

<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" /> 
<link href="@Url.Content("~/Content/themes/base/jquery.ui.dialog.css")" rel="stylesheet" type="text/css" /> 

정리하는 스크립트로드 만 무엇에 넣어, 어떤 JS 오류에 대한 콘솔을 확인하면 필요하고 다시 시도하십시오.

+0

으로 이동하고 JSFIDDLE에서 작동하는 것으로 확인되지만 내 응용 프로그램에서 작동하지 않는 이유를 알 수 없습니다. 스크립트가 제대로로드되고 있는지 확신하지 못한다면 HELLO 경고가 작동하지 않을 것이기 때문입니다. – Claud

+0

오류 없음 BTW,하지만 편집 된 버전을 볼 경우 경고 # 2와 # 3 사이에 대화 스크립트를 넣으면 경고 # 3에 도달하지 않는 것 같습니다. 어떤 아이디어? – Claud

+0

@ Claud25'alert '는 jquery'ready' 함수로 래핑 된 기본 js입니다. 대화 상자와는 달리 jquery를 사용할 필요가 없습니다. 스크립트가 제대로로드되는지 확인하고 불필요한 스크립트를 제거하십시오. 귀하의 코드 예제에서는 두 가지 버전의 jquery 로딩과 두 가지 다른 버전의 jquery 로딩이 있습니다. 이걸 정리해라. 두 가지가 각각 필요하지 않습니다. css도 정리하십시오. –

0

아마도 </body><head> 태그 전에 js 파일의 위치와 관련이있을 수 있습니다. @Scripts.Render("~/bundles/jquery")<head></head> 태그

관련 문제