gpt4 book ai didi

javascript - jquery ui 按钮没有样式

转载 作者:行者123 更新时间:2023-11-28 12:43:15 25 4
gpt4 key购买 nike

我有一个 js 函数,它插入一个表单以响应按钮单击。窗体的底部是一个按钮,也是由该函数添加的。即使我添加了 ui-button 类,新按钮也不会继承 ui css。任何帮助将不胜感激:

var addSite = function(){
var addForm ='<br><input id="site-db" class="manage-sites" type="text" placeholder="Domain" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Domain\'"><br>' +
'<input id="site-table" class="manage-sites" type="text" placeholder="Table" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Table\'"><br>' +
'<input id="site-IP" class="manage-sites" type="text" placeholder="IP Address" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'IP Address\'"><br>' +
'<input id="site-Server" class="manage-sites" type="text" placeholder="Server" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Server\'"><br>' +
'<input id="site-password" class="manage-sites" type="text" placeholder="Password" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Password\'"><br>' +
'<button class="ui-button">Add to Datasites</button>';
$('#manage-sites').html(addForm);
}

相关(?)HTML。这些按钮正确呈现:

<div id="tabs-7">
<!-- Manage Data Sites -->
<h1>Manage Data Sites</h1>
<br><br>
<button id="add-site">Add</button>
<button id="delete-site">Delete</button>
<button id="view-sites">View</button>
<div id="manage-sites" style="margin-top:20px; width:100%">

</div>
<script>
$('#add-site').click(function(){
addSite();
})

</script>


</div>

最佳答案

按钮的 jQuery UI 样式需要的不仅仅是 ui-button类(class)。如果您在 this demo page 上检查 jQuery 按钮的源代码你会注意到按钮也有以下类:

ui-widget ui-state-default ui-corner-all

您可以通过两种方式解决这个问题:

1 - 手动添加类:<button class="ui-button ui-widget ui-state-default ui-corner-all">blah</button>

2 - 添加 html 后,在新创建的元素上调用 jQuery UI 的 button() 方法(我在这里使用 .find())。

$('#manage-sites').html(addForm)
.find('.ui-button').button();

完整演示

$(function(){
var addSite = function(){
var addForm ='<br><input id="site-db" class="manage-sites" type="text" placeholder="Domain" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Domain\'"><br>' +
'<input id="site-table" class="manage-sites" type="text" placeholder="Table" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Table\'"><br>' +
'<input id="site-IP" class="manage-sites" type="text" placeholder="IP Address" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'IP Address\'"><br>' +
'<input id="site-Server" class="manage-sites" type="text" placeholder="Server" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Server\'"><br>' +
'<input id="site-password" class="manage-sites" type="text" placeholder="Password" onfocus="this.placeholder=\'\'" onblur="this.placeholder = \'Password\'"><br>' +
'<button class="ui-button">Add to Datasites</button>';
$('#manage-sites').html(addForm)
.find('.ui-button').button();
};

$('#add-site').click(function(){
addSite();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<div id="tabs-7">
<!-- Manage Data Sites -->
<h1>Manage Data Sites</h1>
<br><br>
<button id="add-site">Add</button>
<button id="delete-site">Delete</button>
<button id="view-sites">View</button>
<div id="manage-sites" style="margin-top:20px; width:100%">

</div>

关于javascript - jquery ui 按钮没有样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25949731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com