简体   繁体   English

在其他项目上应用onclick时如何禁用onclick

[英]How to disable onclick when applying onclick on the other item

Here is my Script,so when I click the first item with a unique id it loads the data but when i click the other item that uses the same function it is added to the first one so i want only the one I click to appear and the other one must be hidden this is inside toggle_visibility. 这是我的脚本,因此,当我单击具有唯一ID的第一项时,它将加载数据,但是当我单击使用相同功能的另一项时,它将被添加到第一项中,因此我只希望单击的项出现并另一个必须隐藏,它位于toggle_visibility中。

function toggle_visibility(id){
  var e = document.getElementById(id);   
  if (e.style.display == 'block')
    e.style.display='none';
  else
    (e.style.display = 'inline-block')
}

you want to show the clicked control only and want to hide all the other controls in document. 您只想显示单击的控件,并且想要隐藏文档中的所有其他控件。 for this you can use below given function(here i am assuming the control is DIV and using jQuery ):- 为此,您可以使用下面给定的功能(在这里我假设控件是DIV并使用jQuery):-

   function toggle_visibility(id){
     $("div").hide();//current passing div or you can pass any tag or selector to hide
     $(id).show();//to show the id's control
   }

above given function will hide all the DIV's except the passed one. 上面给出的函数将隐藏除传递的DIV之外的所有DIV。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM