我正在使用JQuery對一個按鈕HTML元素進行以下更改。必須有更好的寫作方式?將多個屬性更改應用到一個元素
$("#showHide").click(function() {
if ($("#form_password").attr("type") == "password") {
$("#form_password").prop('type', 'text');
$("#showHide").html('Hide');
$("#showHide").removeClass("toggle-hide");
$("#showHide").addClass("toggle-show");
$('#showHide').prop('title', 'Hide Password');
$('#showHide').attr("aria-label","Hide Password");
$('#showHide').attr("aria-pressed","true");
} else {
$("#form_password").prop('type', 'password');
$("#showHide").html('Show');
$("#showHide").removeClass("toggle-show");
$("#showHide").addClass("toggle-hide");
$('#showHide').prop('title', 'Show Password');
$('#showHide').attr("aria-label","Show Password");
$('#showHide').attr("aria-pressed","false");
}
});