在我的模态中我试图将Datatables放在那里,我遇到的问题是宽度不正确,它应该是模态的宽度,但它实际上是这样的
我的jQuery调用Datatables
function getValidTags(){
var ruleID = $('.ruleID').val();
var table = $('.valid-tags').DataTable({
"ajax": {
"url": "/ajax/getValidTags.php",
"type": "POST",
"data": {
ruleID: ruleID
},
},
"columnDefs": [{
"targets": 2,
"render": function(data, type, full, meta){
return '<button class="btn btn-default btn-sm" type="button">Manage</button> <button class="btn btn-danger btn-sm">Delete</button>';
}
}]
});
}
Run Code Online (Sandbox Code Playgroud)
我的HTML
<!-- Modal where you will be able to add new rule -->
<div class="modal fade validation-list-modal" tabindex="-1" role="dialog" aria-labelledby="LargeModalLabel" aria-hidden="true" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-wide">
<div class="modal-content">
<div class="modal-header modal-header-custom">
<input class="ruleID" …Run Code Online (Sandbox Code Playgroud) 我试图在我的socket.io js(index.js)文件中使用jQuery.
每当我尝试做的时候
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="index.js"></script>
<script>
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
socket.on('new user', function(data){
$('#newUserMessage').text(data);
});
</script>
Run Code Online (Sandbox Code Playgroud)
我在控制台中收到此错误
GET http://localhost:3000/index.js
ReferenceError: $ is not defined
Run Code Online (Sandbox Code Playgroud)
我不确定为什么会这样?
但是如果我删除它,我不能在index.js中使用jQuery的函数?
我的index.js文件
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var $usernameInput = $('.usernameInput');
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.broadcast.emit('new user', 'New User Joined, Say Hi :D');
socket.on('chat message', function(msg){ …Run Code Online (Sandbox Code Playgroud)