9 Star 42 Fork 12

没想好/JQ-Bootstrap扩展

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SetMessage.html 3.86 KB
一键复制 编辑 原始数据 按行查看 历史
没想好 提交于 2019-04-02 16:17 . 增加留言功能
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>留言板</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/from/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="css/from/bootstrap-select.css">
<link rel="stylesheet" href="css/bootstrapEx.css">
<script src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/MQTT/paho-mqtt.js"></script>
<script type="text/javascript" src="js/from/global.js"></script>
<script type="text/javascript" src="js/from/jquery.smart-form.js"></script>
<script type="text/javascript" src="js/from/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="js/from/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/from/bootstrap-select.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/from/jquery.validate.js"></script>
<script type="text/javascript" src="js/from/jQuery-Validate-Extend.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrapEx2.0.js"></script>
</head>
<body style="overflow-x:hidden">
<form action="" id="itemForm1"></form>
</body>
<script>
$(document).ready(function(){
ItinPahoClient();
InitForm1();
})
//绘制表单
function InitForm1() {
//清空
$('#itemForm1').html('');
form1 = new bsEx.ItemForm('#itemForm1');
form1.items = [
{ type: 'text', name: 'txtmail', title: '您的联系方式:' },
{ type: 'textarea', name: 'txtmsg', title: '您想说的话:',height:'200px' },
{ type: 'text', name: 'txtname', title: '您的姓名:' },
];//项
form1.requireds = ["txtmsg","txtname"];
//是否启用验证
form1.validate = true;
form1.colunb = 1;//列数
form1.init();//开始显示
var btn = $('#txtname').addbutton("发送");
btn.on('click', function () {
if(form1.valid()){
setmessage();
}
});
btn.loading('链接中...');
}
var sendID,_close;
//核心方法:发送消息
function setmessage() {
sendID = new Date().getTime().toString();
bsEx.ui['txtname-btn'].loading('发送中...');
var v = form1.getFormData();
v.sendID = sendID;
console.log(JSON.stringify(v));
client.publish("MyBlog_set", JSON.stringify(v));
_close = setTimeout(function(){
window.parent.closewindow("发送超时");
},20000)
}
//核心方法:通过MQtt连接
function ItinPahoClient() {
//地址 端口 链接名称(不是主题)
client = new Paho.Client('140.143.155.224', 61614, new Date().getTime().toString());
//监听事件
client.onMessageArrived = function (msg) {
console.log("返回消息"+msg.payloadString)
msg = eval('('+msg.payloadString+')');
console.log("返回消息"+JSON.stringify(msg))
if(msg.sendID == sendID){
clearTimeout(_close);
window.parent.closewindow();
}
};
//失去连接
client.onConnectionLost = function(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("失去连接:"+responseObject.errorMessage);
}
}
//链接配置
client.connect({
onSuccess: function () {
//订阅主题
client.subscribe("MyBlog_done");
bsEx.ui['txtname-btn'].reset();
}
});
}
</script>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/shixixiyue/MyBootstrapEx.git
git@gitee.com:shixixiyue/MyBootstrapEx.git
shixixiyue
MyBootstrapEx
JQ-Bootstrap扩展
master

搜索帮助