javascript 禁用 img 标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8267205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:50:55  来源:igfitidea点击:

Disable img Tag

javascript

提问by Suga

I need to disable img tag using javascript. what is the javascript code?

我需要使用 javascript 禁用 img 标签。什么是javascript代码?

Example :

例子 :

<img id='hrefId' src="/proteus/images/button_find.gif" alt="" />

Please help me

请帮我

回答by Timothy Groote

Here's assuming you mean "hide" by disable

这里假设您的意思是禁用“隐藏”

<style type="text/css">

.disabled 
{
   display:none;
}
</style>


<img id='hrefId' src="/proteus/images/button_find.gif" alt="" />


<script languae="javascript">
var myPicture= document.getElementById('hrefId');
myPicture.className = "disabled";
</script>

回答by solendil

Using jQuery, you can either hide the image : $("#hrefId").hide()or add a CSS class that would style it as being disabled : $("#hrefId").addClass("disabled")...

使用 jQuery,您可以隐藏图像:$("#hrefId").hide()或添加一个 CSS 类,将其样式设置为已禁用:$("#hrefId").addClass("disabled")...

回答by vaisakhrr

    document.getElementById('headname'+(t)).disabled=true;
            document.getElementById('headname'+(t)).setAttribute("class","disabledcombo");
            document.getElementById('img'+(t)).src='../images/editfin.gif' ;
            document.getElementById('new'+(t)).src='../images/adds1.png' ;
            document.getElementById('new'+(t)).className = "disabled";