我使用NodeJS自动从MySQL显示页面信息。如何使文本用户名或说明显示为引导警报,例如“alert alert-info”?
<time></time>
<div id="container">Loading ...</div>
<script src="socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
// create a new websocket
var socket = io.connect('http://localhost:8000');
// on message received we print all the data inside the #container div
socket.on('notification', function (data) {
var usersList = "<dl>";
$.each(data.users,function(index,user){
usersList += "<dt>" + user.user_name + "</dt>\n" +
"<dd>" + user.user_description + "\n" + "</dd>";
});
usersList += "</dl>";
$('#container').html(usersList);
$('time').html('Last Update:' + data.time);
});
</script>
答案 0 :(得分:0)
我会使用带有占位符的预定义(隐藏)模式替换为动态数据,并触发显示通知
类似(通知函数体中的伪代码)
$("#myModal .modal-body").html('my content');
$("#myModal").modal();
(以编程方式触发的bootstrap模态示例)
https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_modal_js&stacked=h