[英]Changing the checkbox with image once the checkbox is clicked
我有一個項目,一旦用戶單擊復選框,便需要更改帶有圖像的復選框。 任何人都可以幫助我。
就目前而言,我只能在單擊復選框后禁用該復選框,
$('.cuttingCheckbox').change(function() {
if (this.checked) {
this.setAttribute("disabled", true);
$.post("process_class.php",{
headmark : this.getAttribute("data-headmark"),
headmark_id : this.getAttribute("data-id"),
columnType : this.getAttribute("data-column")});
}
});
如果要用圖像替換復選框,則可以使用replaceWith
方法。
$(this).replaceWith('<img src="' + src + '"/>');
如果從服務器獲取src
屬性的值,則應緩存該元素並使用post
請求的回調函數:
$('.cuttingCheckbox').change(function() {
if (this.checked) {
var _this = this;
this.disabled = true;
$.post("process_class.php",{
headmark : this.getAttribute("data-headmark"),
headmark_id : this.getAttribute("data-id"),
columnType : this.getAttribute("data-column")
}, function(data) {
$(_this).replaceWith('<img src="' + data.src + '"/>');
});
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.