我一直在努力尋找一種方法來更改標題中的按鈕,而不會丟失格式。我想將帶刪除圖標的刪除按鈕更改爲帶有檢查圖標的完成按鈕。如何使用jQueryMobile刷新標題中的按鈕?
下面的代碼的縮寫版本:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
<script type="text/javascript">
function swapButton() {
$('#button').attr('data-icon', 'check').text('Done').trigger('create');
$('#header').trigger('create');
}
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-position="fixed" id="header">
<a data-icon="delete" id="button" onclick="swapButton()">Delete</a>
<h1>Test Page</h1>
</div>
<div data-role="content">
<p>Click on Delete to get Done button</p>
</div>
</div>
</body>
</html>
這改變了按鈕的文本正常,但所有的格式就會消失。
我試過在按鈕和標題上都用trigger('create')
這個不行,我也試過.page()
這個方法,我在其他地方讀過,我也試過.button()
。
我想不出別的東西要試。
是的,完美的作品!謝謝。 – user1228295 2012-02-29 07:31:30
function swapButton(){ $('#button')。text('Done')。buttonMarkup({icon:'check'}); } – user1228295 2012-02-29 07:47:39