开发者

In JQueryUI, the modal option doesn't work if I'm building and calling the javascript in an external file

开发者 https://www.devze.com 2023-02-02 13:39 出处:网络
I\'m trying to use the dialog widget from JQueryUI and am running into a problem. The code is as follows:

I'm trying to use the dialog widget from JQueryUI and am running into a problem. The code is as follows:

<script type="text/javascript">
   // Set the document ready function...
   $(document).ready(function ()
   {
      // Create the Confirmation Dialog
      var $conf开发者_如何学GoDialog = $("#confDialog")
         .html('This is the confirmation dialog...')
         .dialog({ autoOpen: false, title: 'Email Success!', modal: true });

      // Create the Failure Dialog
      var $failDialog = $("failDialog")
         .html('This is the failure dialog...')
         .dialog({ autoOpen: false, title: 'Email Failed!', modal: true });


      $confDialog.dialog('open');
   });

</script>

If I include this code in the head of the page, the dialog will show as expected and be modal...

If I include this in an external javascript file and reference it like so:

<script src="/Scripts/Main/Contact.js" type="text/javascript"></script>

The dialog box will show up as expected, but it will not be modal... Not sure what the difference here is... Any help would be most appreciated... Thanks!!


It looks like your selector is failing here, causing issues when executed in a different context:

var $failDialog = $("failDialog")

It should be:

var $failDialog = $("#failDialog")

Though kudos on the variable/selector, the naming is dead-on, as it was failing :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号