這是我的問題的更新。現在我已經addede的HTMLBootstrap Modal中的提交按鈕無輸入
// Creating new room
$("#createRoomBtn").click(function(){
var roomName = $("#createRoomName").val();
if (roomName.trim() == "") {
return;
} else {
$("#createRoomName").val("");
socket.emit("serverCreateNewRoom", roomName);
$("#msg").prop("readonly", false);
$("#msg").attr("placeholder", "Your message");
$("#send").attr("disabled", false);
$("#roomModal").modal('hide');
}
});
$(".modal-content").keypress(function(e){
var roomName = $("#createRoomName").val();
if (roomName.trim() == "") {
return;
} else {
if (e.which == 13) {
$("#createRoomName").val("");
socket.emit("serverCreateNewRoom", roomName);
$("#msg").prop("readonly", false);
$("#msg").attr("placeholder", "Your message");
$("#send").attr("disabled", false);
$("#roomModal").modal('hide');
}
}
});
<!--Modal start-->
<div class="modal fade" id="roomModal" tabindex="-1" role="dialog" aria-labelledby="createRoomLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="createRoomLabel">Create room</h4>
</div>
<div class="modal-body">
You can create a chat room here. Names have to be unique.
<form class="form-inline" id="createRoomForm"><input type="text" class="form-control input-lg" placeholder="Room name" id="createRoomName" required /></form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-lg btn-default" data-dismiss="modal">Close</button>
<button data-dismiss="modal" id="createRoomBtn" class="btn btn-success btn-lg">Create room</button>
</div>
</div>
</div>
</div>
<!--Modal end-->
我試圖禁用在引導模式提交按鈕,直到用戶填寫的文字。 「Enter」鍵就像這一點,所以我能理解爲什麼它不會爲按鈕工作
client.js
$("#createRoomBtn").click(function(){
var roomName = $("#createRoomName").val();
if (roomName.trim() == "") {
return;
} else {
$("#createRoomName").val("");
socket.emit("serverCreateNewRoom", roomName);
$("#msg").prop("readonly", false);
$("#msg").attr("placeholder", "Your message");
$("#send").attr("disabled", false);
$("#roomModal").modal('hide');
}
});
$(".modal-content").keypress(function(e){
var roomName = $("#createRoomName").val();
if (roomName.trim() == "") {
return;
} else {
if (e.which == 13) {
$("#createRoomName").val("");
socket.emit("serverCreateNewRoom", roomName);
$("#msg").prop("readonly", false);
$("#msg").attr("placeholder", "Your message");
$("#send").attr("disabled", false);
$("#roomModal").modal('hide');
}
}
});
這實際上比我自己的想法更好 – JonasSH