如何打开 JQuery UI 弹出窗口 onclick
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11906342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open JQuery UI popup onclick
提问by ihorko
I have simple html page:
我有一个简单的 html 页面:
<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!
谢谢!
回答by Adil
id
of element is not supposed to have #
in it if you want to use jQuery selector
as you used in $("#OpenDialog").click(
id
元素是不应该有#
它,如果你想使用jQuery selector
,你在使用$("#OpenDialog").click(
Change
改变
<a id="#OpenDialog" href="#">Click here to open dialog</a>
To
到
<a id="OpenDialog" href="#">Click here to open dialog</a>
回答by Raab
change the id
of the link from #OpenDialog
to OpenDialog
id
将链接从更改#OpenDialog
为OpenDialog
回答by Rachel
The css link and scripts need to go in the head, not the body.
css 链接和脚本需要进入头部,而不是主体。
And as others mentioned, also change the link id from #OpenDialog
to OpenDialog
.
正如其他人所提到的,还将链接 ID 从 更改#OpenDialog
为OpenDialog
。