簡體   English   中英

單擊復選框更改帶有圖像的復選框

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM