用js在页面上,设置多个按钮,点击当前按钮时,当前按钮文字变为“哈哈”,其他未点击的按钮文字变为“呜呜”。
生活随笔
收集整理的這篇文章主要介紹了
用js在页面上,设置多个按钮,点击当前按钮时,当前按钮文字变为“哈哈”,其他未点击的按钮文字变为“呜呜”。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js練習四</title>
<script type="text/javascript">
? ? ? ? window.onload = function () {
? ? ? ? ? ? //1.為每個按鈕注冊單擊事件
? ? ? ? ? ? var inputs = document.getElementsByTagName('input');
? ? ? ? ? ? for (var i = 0; i < inputs.length; i++) {
? ? ? ? ? ? ? ? if (inputs[i].type == 'button') {
? ? ? ? ? ? ? ? ? ? inputs[i].onclick = function () {
? ? ? ? ? ? ? ? ? ? ? ? for (var c = 0; c < inputs.length; c++) {
// ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (inputs[c].type == 'button') {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? inputs[c].value = '嗚嗚';
? ? ? ? ? ? ? ? ? ? ? ? ? ? //}
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? this.value = '哈哈';
? ? ? ? ? ? ? ? ? ? };
? ? ? ? ? ? ? ? };
? ? ? ? ? ? };
? ? ? ? };
? ? </script>
</head>
<body>
<input type="button" name="button" value="" id="btn1">
<input type="button" name="button" value="" id="btn2">
<input type="button" name="button" value="" id="btn3">
<input type="button" name="button" value="" id="btn4">
<input type="button" name="button" value="" id="btn5">
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js練習四</title>
<script type="text/javascript">
? ? ? ? window.onload = function () {
? ? ? ? ? ? //1.為每個按鈕注冊單擊事件
? ? ? ? ? ? var inputs = document.getElementsByTagName('input');
? ? ? ? ? ? for (var i = 0; i < inputs.length; i++) {
? ? ? ? ? ? ? ? if (inputs[i].type == 'button') {
? ? ? ? ? ? ? ? ? ? inputs[i].onclick = function () {
? ? ? ? ? ? ? ? ? ? ? ? for (var c = 0; c < inputs.length; c++) {
// ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (inputs[c].type == 'button') {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? inputs[c].value = '嗚嗚';
? ? ? ? ? ? ? ? ? ? ? ? ? ? //}
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? this.value = '哈哈';
? ? ? ? ? ? ? ? ? ? };
? ? ? ? ? ? ? ? };
? ? ? ? ? ? };
? ? ? ? };
? ? </script>
</head>
<body>
<input type="button" name="button" value="" id="btn1">
<input type="button" name="button" value="" id="btn2">
<input type="button" name="button" value="" id="btn3">
<input type="button" name="button" value="" id="btn4">
<input type="button" name="button" value="" id="btn5">
</body>
</html>
總結
以上是生活随笔為你收集整理的用js在页面上,设置多个按钮,点击当前按钮时,当前按钮文字变为“哈哈”,其他未点击的按钮文字变为“呜呜”。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 影响神经网络训练速度的因素
- 下一篇: 日期加减天数计算,时间戳日期相互转换