【问题标题】:Disabling a div upon some event using jQuery使用 jQuery 在某些事件上禁用 div
【发布时间】:2013-01-11 06:10:43
【问题描述】:

我有一张图片

<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');
}

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

【问题讨论】:

标签: jquery button image javascript


【解决方案1】:

disabled 属性用于表单控件

以下元素支持禁用属性:BUTTON、INPUT、OPTGROUP、OPTION、SELECT 和 TEXTAREA。

您可以改为使用 &lt;input type="image" /&gt; 元素

禁用图像输入内联使用:... onclick="this.disabled = true" /&gt;


demo jsfiddle (pure JavaScript)

demo jsfiddle (jQuery)

【讨论】:

  • 当我使用 时,我可以禁用图像。但我想执行一个功能,然后在单击时禁用该按钮。我试过 ...onclick="execute();this.disabled=true;"但它没有用。以后我也想启用它。
【解决方案2】:

请将代码改成这个并尝试...

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

【讨论】:

    猜你喜欢
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    相关资源
    最近更新 更多