jquery - 使用 jQuery 在某些事件上禁用 div

标签 jquery button image javascript

我有一张图片

<div id="map-viewer-button"><img src="image/Btn1.png"
                    onmouseover="this.src='image/Btn2.png'"
                    onmouseout="this.src='image/Btn1.png'"
                    onmousedown="this.src='image/Btn3.png'"
                    onmouseup="this.src='image/Btn2.png'"               
                    onclick="disableButton()" width="200px" height="100px"></div>

我想在单击图像后禁用该图像。并在其他情况发生时启用它。

function disableButton(){
        $('#map-viewer-button :input').attr('disabled', true);
}
function enableButton(){
        $('#map-viewer-button :input').removeAttr('disabled');
}

但这不起作用。可能是什么原因?还有其他方法吗?

最佳答案

disabled 属性用于表单控件

The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.

您可以使用 <input type="image" />元素

要禁用图像输入内联使用:... onclick="this.disabled = true" />

<小时/>

demo jsfiddle (pure JavaScript)

demo jsfiddle (jQuery)

关于jquery - 使用 jQuery 在某些事件上禁用 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14272667/

相关文章:

delphi - 如何知道按钮被点击了多少次?

css - 滑动门按钮元素仅在 Firefox 中损坏

javascript - 将运算符存储为变量

javascript - 滑动框错误

javascript - 使用 jQuery 处理使用 Newtonsoft.Json 发送的 json 数据

image - 如何生成纹理映射图像?

html - 使用 CSS 的严格 HTML 中的图像边框

JavaScript/JQuery --> 每次单击与该函数链接对应的函数时都重新运行该函数

android - 在android中以编程方式设置按钮半径

image - HTML5如何在canvas中绘制透明像素图片