我想在我的页面上按下按钮后禁用该按钮。然后,当我进入收藏夹页面并从那里删除项目时,按钮应该重新出现,但我不知道该怎么做。
我能得到一些帮助吗?
$(document).ready( function() {
$("#add_btn").on("tap", function(){
var propName = $("#propName").text();
var propPrice = $("#propPrice").text();
var pageURL = $(location).attr("href");
localStorage.setItem("propName", propName);
localStorage.setItem("propPrice", propPrice);
localStorage.setItem("prop", pageURL);
$('#pFave').html("Property added to Favourites");
$("#popupFave").popup("open", "reposition", 'positionTo: window');
});
var propLength = window.localStorage.length;
console.log(propLength);
if(propLength !=0){
var hName = localStorage.getItem("propName");
var hPrice = localStorage.getItem("propPrice");
var url = localStorage.getItem("prop");
var list = "<li><a href='"+ url +"' data-ajax='false'>" +hName +"<br> "+hPrice + "</a><button id='remove' class='ui-btn ui-corner-all'>Delete</button></li>";
$('#listProperties').append(list).listview('refresh');
$('#remove').on("tap", function(){
localStorage.removeItem("propName");
localStorage.removeItem("propPrice");
localStorage.removeItem("prop");
window.location.reload();
});
} else {
var list = "<li data-icon='false'><a href='#' data-ajax='false'>No Properties Saved</a></li>";
$('#listProperties').append(list).listview('refresh');
}
});
<div data-role="popup" id="popupFave" data-overlay-theme="a" data-theme="a" data-dismissible="false" style="max-width:300px;">
<div role="main" class="ui-content">
<h3 id='pFave'> </h3>
<a href="#" class="ui-btn ui-corner-all " data-rel="back">Ok</a>
</div>
</div>
<button id="add_btn" data-icon="star">Add to favourites</button>
要禁用按钮:$("#add_btn").attr("disabled", true);
要启用按钮,您可以使用$('#add_btn').attr("disabled", false);
或$('#add_btn').removeAttr("disabled");