[英]jQuery can change the text of input submit type but button is no longer clickable
我正在使用 jaquery 和 jquery 移動版 1.8,我有一個像這樣的按鈕:
<div class="ui-bar-a" id="myButton" style="bottom:0;position: fixed;width: 100%">
<input type="submit" name="Next" id="NextButton" value="Save" />
</div>
我有一個 javascript 可以像這樣更改它的文本:
$('#AnyButton').live('click', function() {
if(true)
{
$('#myButton div').text('Saving')
}
else
$('#myButton div').text('Continue');
});
我嘗試了許多其他不起作用的方法,但這有效,但是在我更改文本后,按鈕似乎將 myButton div 內容替換為文本“保存”或“繼續”,因此該按鈕不再可點擊。
在我的瀏覽器調試器中,按鈕會在 myButton 和 Nextbutton 輸入之間顯示一個文本 Save。
像這樣:
<div class="ui-bar-a" id="myButton" style="bottom:0;position: fixed;width: 100%">
"Save"
<input type="submit" name="Next" id="NextButton" value="Save" />
</div>
如果我正確閱讀了您的帖子,您想更改輸入的文本,您需要更改它的 value 屬性。 我認為.live
相對較舊且已棄用,應替換為.on
和委托的事件處理程序
$('#AnyButton').live('click', function() {
if(true)
$('#myButton').find('input[type="submit"]').val('Saving');
else
$('#myButton').find('input[type="submit"]').val('Continue');
});
我懷疑您的代碼比您提供的更多。 對於 jQuery Mobile,每個input
都被讀取為一個按鈕。 所以你可能需要在動態更新后刷新它。
此代碼有效:
$(function() { $("#NextButton").click(function(e) { e.preventDefault(); $(this).val("Saving").button("refresh"); }); });
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <div class="ui-bar-a" id="myButton" style="bottom:0;position: fixed;width: 100%"> <input type="submit" name="Next" id="NextButton" value="Save" /> </div>
查看更多: https://api.jquerymobile.com/button/和https://demos.jquerymobile.com/1.4.5/button/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.