当您输入用户名并单击“提交”按钮时,我正在尝试使用此用户名登录系统作为聊天框,这会将用户名设置为输入的文本。我正在使用Scaledrone处理消息和用户名等。
<html>
<head>
<script type='text/javascript' src='https://cdn.scaledrone.com/scaledrone.min.js'></script>
<!--<script type='text/javascript' src='http://0.0.0.0:8080/scaledrone.js'></script>-->
</head>
<body>
<div id="Chat" style="display: none">
<div class="members-count">0 users in room:</div>
<div class="members-list">No one seems to be here</div>
<div class="messages"></div>
<form class="message-form" onsubmit="return false;">
<input class="message-form__input" placeholder="Type a message.." type="text"/>
<input class="message-form__button" value="Send" type="submit"/>
</form>
</div>
<div id="Login">
<p>Username:
<input type="text" name="text1">
</p>
<p>Password:
<input type="password" name="text2">
</p>
<input type="button" value="Log In" name="Submit" onclick="onClickHandler()" >
</div>
<script>
function onClickHandler() {
validate(document.getElementsByName("text1")[0].value,"t",document.getElementsByName("text2")[0].value,"t");
}
function validate(text1,text2,text3,text4) {
if (text1 === text2 && text3 === text4) {
var login = document.getElementById("Login");
var chat = document.getElementById("Chat");
Login.style.display = "none";
Chat.style.display = "block";
}
}
</script>
<script src="./script.js"></script>
</body>
</html>
在script.js文件中...
const drone = new ScaleDrone(CLIENT_ID, {
data: { // Will be sent out as clientData via events
name: getName(),
color: getRandomColor(),
},
});