jquery - 如何通过单击按钮并将按钮变成使用 jQuery 选择的图像来接受图像?

标签 jquery html css

我正在准备一个注册页面,允许用户通过在其客户端中选择来源来插入照片。该按钮必须转换为所选图像。

谢谢

最佳答案

使用javasript和CSS

$('#button').click(function(){
        if($(this).hasClass('HasImage'))
        {
            $(this).addClass('RemoveImage').removeClass('HasImage');
        }
        else
        {
            $(this).addClass('HasImage').removeClass('RemoveImage');
        }
    });

CSS

.HasImage{background: url('path of image') }
.RemoveImage{background: url('path of image')}

关于jquery - 如何通过单击按钮并将按钮变成使用 jQuery 选择的图像来接受图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28713723/

相关文章:

javascript - 用于减少要编写的 javascript 行数的技术

javascript - 如何在 Prestashop 1.6 中调用将跨度添加到输入、单选按钮的函数

html - 如何让表单变得响应式?

css - 在 JavaFX 中为 TextFieldTableCell 创建有效性检查

javascript - 刷新时 HTML/Javascript/CSS 可折叠菜单不会保持关闭状态

javascript - 无法弄清楚如何在 jQuery 中正确使用 $(this) 来获取悬停元素

jquery - 等待事件发生,然后再在JQuery中执行其他操作

javascript - 检测 url/链接并用 img 标签替换图像并用 href 替换链接

javascript - angularjs-脚本没有输出

javascript - 您如何获得表格 odd tr 并更改样式?