<!DOCTYPE html>
<html lang="en">
<head>
???<meta charset="UTF-8">
???<title>Title</title>
</head>
<body>
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<input type="button" value="没怀孕">
<script>
???var btnObjs=document.getElementsByTagName("input");
???????for (var i=0;i<btnObjs.length;i++) {
???????????btnObjs[i].onclick=function () {
???????????????for(var j=0;j<btnObjs.length;j++){
???????????????????btnObjs[j].value="没怀孕";
???????????????}
???????????????this.value="怀孕了";
???????????};
???????}
</script>
</body>
</html>
js排他功能示例
原文地址:https://www.cnblogs.com/Yanss/p/10293795.html