如何在节点js中使用jquery。请帮我 我正在使用此代码
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM('<!DOCTYPE html>');
const $ = require('jquery')(window);
var connection = require('./database');
connection.query(
"SELECT * FROM cr_state",
function(error, results, fields) {
if (error) throw error;
$('#state').html('<option value="1">test</option>')
}
);
但是此代码不起作用。如何使用jquery?
答案 0 :(得分:1)
默认情况下,Nodejs并非旨在读取DOM
Date date = d.parse(value);
Calendar c = Calendar.getInstance();
c.setTime(date);
int dd = c.get(Calendar.DAY_OF_MONTH);
int mmm = c.get(Calendar.MONTH) + 1;
int yyyy = c.get(Calendar.YEAR);
String dateString = "" + dd + "-" + mmm + "-" + yyyy;
如果要使用node读取DOM,则必须安装DOM解析器。
有关更多信息:Why doesn't Node.js have a native DOM?
并安装DOM解析器:How do I parse a HTML page with Node.js