我想使用jquery ui,但我缺少以下环境中的css:
$.ajax({
url: '//code.jquery.com/ui/1.12.1/jquery-ui.js',
dataType: 'script',
cache: true,
success: function() {
$( "#dialog" ).dialog();
}
});
$( "body" ).append('<div id="dialog" title="Basic dialog"><p>test</p></div>');
相信我错过了这部分:
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
如何使用 jquery ui 框架中的样式?链接:https://jqueryui.com/dialog/#default
在
<head> </head>
标签之间定义以下代码,您可以使用 Jquery UI 的所有功能。
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
当您希望后端和前端之间进行异步通信时,会进行 ajax 调用。请删除 ajax 调用并继续开发您的代码。谢谢
你需要添加这个
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
插入 <head>
文件中的 HTML
标签。
查看文档:https://jqueryui.com/dialog/#default
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#dialog" ).dialog();
} );
</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>
</body>
</html>
您可以使用
css
将 head
文件附加到 appendTo()
标签:
$.ajax({
url: '//code.jquery.com/ui/1.12.1/jquery-ui.js',
dataType: 'script',
cache: true,
success: function() {
$("#dialog").dialog();
$("<link/>", {
rel: "stylesheet",
type: "text/css",
href: "//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"
}).appendTo("head");
}
});
$("body").append('<div id="dialog" title="Basic dialog"><p>test</p></div>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#dialog" ).dialog();
} );
</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>
</body>
</html>