2018 ソフトウェア設計及び演習用の班Wiki
18::gr08::user
プログラム
<html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="play-day-background.css" type="text/css"> <link rel="stylesheet" href="button.css" type="text/css"> <link rel="stylesheet" href="moji.css" type="text/css"> <style type="text/css"> body{ font-family: font-demo1; font-size: 22px; } </style> <title>ユーザー登録</title> </head> <body> <audio src="click.wav" preload="auto" autoplay ></audio> <audio id="sound" preload="auto"> <source src="click.wav" type="audio/wav"> </audio> <center> <br><br><br><br><br><br><br> <h1>ユーザー名を登録します</h1> <br><br><br><br><br><br><br><br> <input type="text" id="name_input" style="width:200px; height:50px" /> <button onclick="user();" class="square_btn" > OK </button> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <div id="msg"></div> <script src="/socket.io/socket.io.js"></script> <script type="text/javascript"> var socketio = io.connect(); socketio.on("connected", function(name) {}); socketio.on("disconnect", function () {}); socketio.on("namecheck", function (data) { if(data == 1){ document.getElementById('msg').innerHTML = "使用済みです"; } else if(data == 2){ console.log("定員の超過"); document.getElementById('msg').innerHTML = "定員を超過します"; } else{ window.location = 'story.html'; } document.getElementById('name_input').focus(); }); function user() { var myname = document.getElementById('name_input').value; if(myname == ''){ document.getElementById('msg').innerHTML = "使用不能な文字列です"; document.getElementById('name_input').focus(); }else{ socketio.emit("cname", {value: myname}); sessionStorage.setItem("myname" , myname); name.value = ''; } } document.getElementById('name_input').onkeydown = function(e){ if(e.keyCode =="13"){ user(); } } document.getElementById('name_input').focus(); </script> </body> </html>
最終更新日:2018/08/03 12:27:14