我使用jQuery的2.1.0.min.js和jquery.ui-1.10.4。
這裏是我的全部源代碼:
(For the jquery-ui.css link tag, change: href="path_to_your_jquery-ui/themes/base/jquery-ui.css")
(For the jquery script tag, change: src="path_to_your_jquery/jquery-2.1.0.min.js")
(For the jquery-ui script tag, change: src="path_to_your_jquery-ui/ui/jquery-ui.js")
(For your demos.css link tag, change: href="path_to_your_jquery-ui/demos/demos.css")
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="add-ons/jui/themes/base/jquery-ui.css"/>
<script src="add-ons/jquery-2.1.0.min.js"></script>
<script src="add-ons/jui/ui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="add-ons/jui/demos/demos.css"/>
<!-- this in-file styling is used to hide the #dialog element initially -->
<style>
#dialog {
display: none;
}
</style>
<script>
$(document).ready(function() {
$("#put").on("click", function(evnt) {
$(function() {
$("#dialog").dialog({
width:250,
height: 180,
modal:true
});
});
evnt.preventDefault();
});
});
</script>
</head>
<body>
<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>
<div>
<button type="button" id="put">Insert data</button>
</div>
</body>
</html>
請務必事件參數傳遞給你的回調函數在您的「在點擊」功能,調用preventDefault()方法就可以了。瞭解更多關於event.preventDefault()此外,here的上event.preventDefault(一個良好的閱讀)與返回false
$(函數(){ 警報( 「你好」); }); – P6345uk 2013-04-24 15:52:29
(這確保你已經包含了jquery js文件) – P6345uk 2013-04-24 15:52:56
檢查你的控制檯。你有錯誤嗎? – Dom 2013-04-24 18:37:06