我在使下面的简单脚本工作时遇到问题,但事实并非如此:
<div data-role="page" id="targetPage">
<div data-role="content">
<form action="" method="" name="targetForm">
<a id="bt-addTarget" data-role="button" data-icon="plus">Add Target</a>
</form>
</div><!-- /content -->
<div id="addTargetDialog" data-role="dialog">
<div data-role="header" data-theme="d">
<h1>Choose a Target</h1>
</div>
<div data-role="content" data-theme="c">
<form action="" method="" name="addTargetForm">
<input type="hidden" name="addTarget" value="yes" />
<select name="target">
<option value="test 1">test 1</option>
<option value="test 2">test 2</option>
</select>
<a id="btn-apply" href="target.php" data-role="button" data-theme="b">Apply</a>
<a href="target.php" data-role="button" data-rel="back" data-theme="c">Cancel</a>
</form>
</div>
</div>
<script>
$(document).undelegate("#targetPage", "pageinit").delegate("#targetPage", "pageinit", function() {
$('form[name="targetForm"] #bt-addTarget').off('click').on('click', function(e){
e.preventDefault();
$.mobile.changePage("#addTargetDialog");
});
});
</script>
</div>
$.mobile.changePage("#addTargetDialog"); 被调用但失败