开发者

jQuery.simpleDialog box not showing

开发者 https://www.devze.com 2023-01-26 15:40 出处:网络
I\'m trying to get a \"simpleDialog\" box to open up via a link using the following code: <script language=\"javascript\" type=\"text/javascript\">

I'm trying to get a "simpleDialog" box to open up via a link using the following code:

<script language="javascript" type="text/javascript"> 
jQuery(document).ready(function () {
    jQuery('.simpledialog').simpleDialog();
});

jQuery('#sdHc2').simpleDialog({
  showCloseLabel: false
});

});
</script>

Here's the link I'm using:

<a href="#" id="sdHc2" class="medium" rel="simpleDialog2">request a call back</a>

And the div I want to display:

<div style="display:none;" id="simpleDialog2">
 <h3>Form content</h3>
 <p>This is where the form will go.</p>
 <a href="#" class="close">close</p></a>
</div>

I've called the jquery.simpledialog.js script 开发者_开发百科in the head along with the jquery.simpledialog.css but for some reason the dialog box is not showing up.

I have a show/hide script running on the page which works fine so what am I missing to get the dialog box to show up?


You have an extra set of }) tags in there, meaning you're a) getting and error and b) jQuery('#sdHc2') isn't running on document.ready, it should look like this:

jQuery(document).ready(function () {
    jQuery('.simpledialog').simpleDialog();
    jQuery('#sdHc2').simpleDialog({
      showCloseLabel: false
    });
});

I would simplify it overall with a common class on the links though, like this:

<a href="#" class="medium dialogLink" rel="simpleDialog2">request a call back</a>

Then bind them all at once instead of per-id like this:

jQuery(document).ready(function () {
    jQuery('.dialogLink').simpleDialog({
      showCloseLabel: false
    });
});

This way you don't have to change your code at all as you add links, just add as many link/dialog pairs in the page as you want.

0

精彩评论

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

关注公众号