Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jQuery Mobile中动态添加页面不工作_Jquery_Ajax_Mobile_Jquery Mobile - Fatal编程技术网

在jQuery Mobile中动态添加页面不工作

在jQuery Mobile中动态添加页面不工作,jquery,ajax,mobile,jquery-mobile,Jquery,Ajax,Mobile,Jquery Mobile,当我在jQuery Mobile中创建一个全新的页面时,页面被创建,但是当我单击id链接到刚刚创建的页面的链接时,它就不起作用了。列表项链接保持选中状态(蓝色,在标准主题中),但页面本身不加载 通过将页面附加到正文中来创建页面: $('body').append('<div id="' generatedId '" data-role="page"><div data-role="header"><h2>Page</h2></div>&

当我在jQuery Mobile中创建一个全新的页面时,页面被创建,但是当我单击id链接到刚刚创建的页面的链接时,它就不起作用了。列表项链接保持选中状态(蓝色,在标准主题中),但页面本身不加载

通过将页面附加到正文中来创建页面:

$('body').append('<div id="' generatedId '" data-role="page"><div data-role="header"><h2>Page</h2></div><div data-role="content">content</div></div>');
$('body')。追加('Pagecontent');
当我关闭jquerymobile时,您可以清楚地看到页面已经创建,但是使用jQM无法访问


我做错了什么?

以下几点对我很有用

<!DOCTYPE html>
<html>
 <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<!-- standard Jquery/jQuery Mobile Libraries -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />   
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>   
<script type="text/javascript">
$(document).ready(function(){
    for(i=0;i<3;i++){
        $('body').append('<div id="test'+i+'" data-role="page"><div data-role="header"><h2>Page'+i+'</h2></div><div data-role="content">content'+i+'</div></div>');
    }
});
</script>
</head> 

<body>  
<div data-role="page" id="mainmenu">
    <div data-role="header"><h1>Sample Home</h1></div>
    <div class="ui-body ui-body-c">
        <div data-role="content">   
            <a href="#test0" class="preShowHTML">Sample 1</a>     
            <a href="#test1" class="preShowHTML">Sample 2</a>     
            <a href="#test2" class="preShowHTML">Sample 3</a>                               
        </div>      
    </div>          
</div>

$(文档).ready(函数(){

对于(i=0;i)您使用的是哪个版本的jQuery Mobile?能否将示例代码添加到jsbin.com?它应该可以正常工作,也许问题出在其他地方?对于1.0b3,您可以尝试以下操作:
$('body')。append('Pagecontent')。trigger('create');