2

我正在尝试生成带有一些标题文本的标题,但添加的动态内容不支持 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>
4

1 回答 1

3

要动态创建[data-role=header]和创建[data-role=footer],您需要使用$('[data-role=page]').trigger('pagecreate');.

jQuery Mobile 中的每个小部件都应该使用createpagecreateupdatelayout来增强refresh。使用这些方法取决于您要增强的项目。检查此以获取有关增强动态内容的更多信息。

演示

附加新标题后,添加

$('[data-role=page]').trigger('pagecreate');
于 2013-05-19T07:17:20.670 回答