Home > Web Front-end > JS Tutorial > JavaScript method to automatically eliminate button function_javascript skills

JavaScript method to automatically eliminate button function_javascript skills

WBOY
Release: 2016-05-16 15:47:05
Original
1219 people have browsed it

The example in this article describes how to use JavaScript to automatically eliminate the button function. Share it with everyone for your reference. The details are as follows:

Here, JavaScript is used to automatically eliminate the content displayed in the previous item and display the content in a specific position of the web page. The first button is available, but the second one cannot be used after the first click. If you want the second button to activate function, you need to eliminate its function. For example, this sample code implements such a function.

The operation effect is as shown below:

The specific code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>JavaScript自动消除前项显示的内容</title>
<style type="text/css">
body{padding:20px;background:#333;}
h1{color:white;}
em{width:100px;height:100px;background:#EEE;border:1px #CCC solid;padding:10px;cursor:pointer;}
div{width:100px;height:100px;background:#444;margin:10px;display:none;color:white;text-align:center;line-height:100px;}
</style>
</head>
<body> 
  <h1>鱼与熊掌不可兼得</h1>
  <br />
 <em>我要鱼</em>
 <em>我要熊掌</em>
 <div id="a">鱼</div>
 <div id="b">熊掌</div>
<script type="text/javascript">
window.onload=function(){
  var abtn=document.getElementsByTagName("em")[0];
  var bbtn=document.getElementsByTagName("em")[1];
  var a=document.getElementById("a");
  var b=document.getElementById("b");
  abtn.onclick=function(){
    a.style.display="block";
    bbtn.onclick=null;
  }
  bbtn.onclick=function(){
    b.style.display="block";
    abtn.onclick=null;
  }
}   
</script>
</body>
</html>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template