How to open JQuery UI popup onclick

限于喜欢 提交于 2019-12-10 03:37:00

问题


I have simple html page:

<html>
<head>
<title></title>
</head>
<body>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>


    <script type="text/javascript">
        $(document).ready(function () {
            $("#OpenDialog").click(function () {
                $("#dialog").dialog({modal: true, height: 590, width: 1005 });
            });
        });
    </script>
    <a id="#OpenDialog" href="#">Click here to open dialog</a>
    <div id="dialog" title="Dialog Title">
        <p>test</p>
    </div>

</body>
</html>

I need to have popup content hidden and when click on the link open a dialog.

What I'm wrong with in my code?

Thanks!


回答1:


id of element is not supposed to have # in it if you want to use jQuery selector as you used in $("#OpenDialog").click(

Change

<a id="#OpenDialog" href="#">Click here to open dialog</a>    

To

 <a id="OpenDialog" href="#">Click here to open dialog</a>



回答2:


change the id of the link from #OpenDialog to OpenDialog




回答3:


The css link and scripts need to go in the head, not the body.

And as others mentioned, also change the link id from #OpenDialog to OpenDialog.



来源:https://stackoverflow.com/questions/11906342/how-to-open-jquery-ui-popup-onclick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!