js排他功能示例

<!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>
posted @ 2019-01-20 00:03  燕十三丶  阅读(648)  评论(0编辑  收藏  举报
AmazingCounters.com