gpt4 book ai didi

javascript - Javascript 插入的内容跟不上样式

转载 作者:行者123 更新时间:2023-11-30 10:39:10 25 4
gpt4 key购买 nike

考虑最后给出的代码,它使用 jQuery Mobile 来增强按钮。

页面加载时出现第一个按钮(原始按钮): enter image description here

第二个按钮(inserted按钮)是点击黄色框插入: enter image description here

这里的问题是,插入的按钮跟不上 CSS 样式。当我们使用 AJAX 时,这种情况非常常见(并不特定于 jQuery Mobile),但我一直无法找到解决此问题的方法或解决方法。

如何使用 CSS 样式增强插入的按钮?

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>

<script type="text/javascript">
function insert(){
$("#result").html('<input type="button" value="Inserted button"/>');
}
</script>

</head>
<body>
<form>

<p class="ui-body-e ui-corner-all" style="padding:5px" onclick="insert()">Click here to insert the button</p>

<input type="button" value="Original button" />

<div id="result">
Button not inserted yet
</div>

</form>
</body>
</html>

最佳答案

插入按钮的 html 后:

$("#result").html('<input type="button" value="Inserted button"/>');

您可以在其容器上调用 .trigger('create') 以在其内容上调用 jQuery-mobile 渲染器,因此您的行将如下所示:

$("#result").html('<input type="button" value="Inserted button"/>').trigger('create');

关于javascript - Javascript 插入的内容跟不上样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12144150/

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