【问题标题】:Check box replaced by an image after on click in HTML在 HTML 中单击后,复选框被替换为图像
【发布时间】:2011-08-22 10:14:01
【问题描述】:

我想在 HTML 的复选框中添加图像,这样当我单击复选框时,它应该被图像替换。有什么方法可以做到?

【问题讨论】:

标签: html


【解决方案1】:

设 cb 为复选框,src 为要显示的图片来源。

cb.onclick = function(){
    if(!this.img){
        var img = this.img = document.createElement("image");
        img.src=src;
        img.cb = this;
        img.onclick = function(){
            this.parentNode.replaceChild(this.cb,this);
            }
        }
    this.parentNode.replaceChild(this.img,this);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-21
    • 2012-06-06
    • 1970-01-01
    • 2020-12-05
    • 2016-04-20
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多