首页 > 代码库 > HTML <button>标签

HTML <button>标签

如果<button>标签在<form>中不加type=“button”,那么默认含义是“submit”。

<button>标签里面disabled属性使其不可用,常见javascript修改disabled属性实例:(a键b键互相撕逼)

<style>
  #a,#b
  {
  height:30px;
  width:70px;
  background:yellow;
  box-sizing:border-box;
  }

  
  
  
  </style>
 </head>
 <body>
 <button type="button" id="a" onclick="an()" >会变色</button>
 <button type="button" id="b" onclick="bn()" >会变色</button>
	<script>

	function bn()
	{

		if(document.getElementById("b").disabled!="true")

		{
			document.getElementById("b").disabled="true";
			document.getElementById("b").style.background="gray";
			document.getElementById("a").removeAttribute("disabled");
			document.getElementById("a").removeAttribute("style");
		}
		else
		{
			document.getElementById("a").disabled="true";
			document.getElementById("a").style.background="gray";
			document.getElementById("b").removeAttribute("disabled");
			document.getElementById("b").removeAttribute("style");
		}

	}
	function an()

	{

		if(document.getElementById("a").disabled!="true")
		{
			document.getElementById("a").disabled="true";
			document.getElementById("a").style.background="gray";
			document.getElementById("b").removeAttribute("disabled");
			document.getElementById("b").removeAttribute("style");
		}
		else
		{
			document.getElementById("b").disabled="true";
			document.getElementById("b").style.background="gray";
			document.getElementById("a").removeAttribute("disabled");
			document.getElementById("a").removeAttribute("style");
		}
	}
	</script>
</body>

  

 

HTML <button>标签