下面是主题更改功能,它运行正常。
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="stylesheet" href="css/theme.css">-->
<link rel="stylesheet" href="http://demos.jquerymobile.com/1.4.0/theme-classic/theme-classic.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$( document ).on( "pagecreate", function() {
$( "#theme-selector input" ).on( "change", function( event ) {
var themeClass = $( "#theme-selector input:checked" ).attr( "id" );
$( "#testpage" ).removeClass( "ui-page-theme-a ui-page-theme-b ui-page-theme-c ui-page-theme-d ui-page-theme-e" ).addClass( "ui-page-theme-" + themeClass );
});
});
</script>
</head>
<body>
<div data-role="page" id="testpage">
<div data-role="header">
<h1>Untitled App</h1>
</div>
<div data-role="main" class="ui-content">
<form class="ui-mini">
<div class="ui-field-contain" id="theme-selector">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Theme:</legend>
<label for="a">A</label>
<input type="radio" name="theme" id="a" checked>
<label for="b">B</label>
<input type="radio" name="theme" id="b">
<label for="c">C</label>
<input type="radio" name="theme" id="c">
<label for="d">D</label>
<input type="radio" name="theme" id="d">
<label for="e">E</label>
<input type="radio" name="theme" id="e">
</fieldset>
</div>
</form>
</div>
<div data-role="footer">
<h1>Footer Text</h1>
</div>
</div>
</body>
</html>
我已经创建了另一个页面并使用iframe来加载页面。我还将功能和按钮移到了这个页面上。
loader.html
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
$( document ).on( "pagecreate", function() {
$( "#theme-selector input" ).on( "change", function( event ) {
var themeClass = $( "#theme-selector input:checked" ).attr( "id" );
$( "#testpage" ).removeClass( "ui-page-theme-a ui-page-theme-b ui-page-theme-c ui-page-theme-d ui-page-theme-e" ).addClass( "ui-page-theme-" + themeClass );
});
});
</script>
</head>
<body>
<div align="center">
<form class="ui-mini">
<div class="ui-field-contain" id="theme-selector">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Theme:</legend>
<label for="a">A</label>
<input type="radio" name="theme" id="a" checked>
<label for="b">B</label>
<input type="radio" name="theme" id="b">
<label for="c">C</label>
<input type="radio" name="theme" id="c">
<label for="d">D</label>
<input type="radio" name="theme" id="d">
<label for="e">E</label>
<input type="radio" name="theme" id="e">
</fieldset>
</div>
</form>
<iframe src="index.html" id="resultFrame" seamless width="320" height="568" style="border:1px solid #999;"></iframe>
</div>
</body>
</html>
表单不再有效。有没有办法让函数调用iframe中的id?