我正在尝试使用一些标题文本生成标题,但添加的动态内容不支持JQuery Mobile主题。当添加任何其他按钮,输入文本框等时,会出现相同的结果:等:是否还有解决此问题的方法?
这是我的小提琴 - http://jsfiddle.net/fABC7/
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Website Title</title>
<meta name='Description' content="Describe your website here...">
<meta http-equiv='Content-Type' charset='utf-8' content='text/html;charset=ISO-8859-1'>
<meta name='Keywords' content='words, describing, your, website'>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<style type="text/css">
</style>
<script type='text/javascript'>
$(document).ready(function() {
var fixgeometry = function() {
/* Some orientation changes leave the scroll position at something
* that isn't 0,0. This is annoying for user experience. */
scroll(0, 0);
/* Calculate the geometry that our content area should take */
var header = $(".header:visible");
var footer = $(".footer:visible");
var content = $(".content:visible");
var viewport_height = $(window).height();
var content_height = viewport_height - header.outerHeight() - footer.outerHeight();
/* Trim margin/border/padding height */
content_height -= (content.outerHeight() - content.height());
content.height(content_height);
}; /* fixgeometry */
$(window).bind("orientationchange resize pageshow", fixgeometry);
$("input#submitheader").click(function() {
var headeropen = "<div data-role='header' "
var headercloseopenmark = "'>"
var headerheadingopen = "<h1>"
var pageheaderheading = $("input#headerheading").val();
var headerheadingclose = "</h1>"
var headerclose = "</div>"
$("#1stpagename").append((headeropen) + (headercloseopenmark) + (headerheadingopen) + (pageheaderheading) + (headerheadingclose) + (headerclose));});
});
</script>
</head>
<body>
<div data-role="page" class="pages" id="1stpagename">
<div id="genoptions">
Theme:<br>
<select name="selectthemeheader">
<option value="a" selected="selected">Black</option>
<option value="b">Blue</option>
<option value="c">Gray</option>
<option value="d">Light Gray</option>
<option value="e">Yellow</option>
</select><br><br>
Fixed:<br>
<select name="selectfixedheaderoption">
<option value="1">Yes</option>
<option value="2" selected="selected">No</option>
</select><br><br>
Heading:<br>
<input type="text" id="headerheading" placeholder="My Website" value="Placeholder"><br><br>
Heading Size:<br>
<select name="selectheaderheadingsize">
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected="selected">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select><br><br>
<input value="Submit" type="submit" id="submitheader">
</div>
</div>
</body>
</html>
答案 0 :(得分:3)
要动态创建[data-role=header]
和[data-role=footer]
,您需要使用$('[data-role=page]').trigger('pagecreate');
来增强标记。
应使用create
,pagecreate
,updatelayout
或refresh
增强jQuery Mobile中的每个小部件。使用这些方法取决于您要增强的项目。有关Enhancing Dynamic Contents的更多信息,请查看此内容。
<强> Demo 强>
添加新标题后,添加
$('[data-role=page]').trigger('pagecreate');