理解node.js/express中的EJB
我是node.js的新手,使用EJS让我很为难。我非常习惯HTML/jQuery。但是我无法使jquery与EJS一起工作 当我试图通过表单操作在EJS中使用HTTPGET/post时,它是有效的。 其他的都不行理解node.js/express中的EJB,node.js,express,ejs,Node.js,Express,Ejs,我是node.js的新手,使用EJS让我很为难。我非常习惯HTML/jQuery。但是我无法使jquery与EJS一起工作 当我试图通过表单操作在EJS中使用HTTPGET/post时,它是有效的。 其他的都不行 **HTML** <head> <title><%= title %></title> </head> <body> <h1><%= title %></h1> <
**HTML**
<head>
<title><%= title %></title>
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= name %></p>
<div>
<form action="/room1/getTemp" method="get">
<input type="submit" id="getTempBtn" value="Get Temperature"/>
<label>Temperature is: </label>
<input type="text" id="tempID" value= <%= temperatureValue %>>
</form>
<div id="div1">
<input type="button" id="getDistance" value="Get Distance">
<input type="text" id="distTxt" value= <%= distanceValue %>>
</div>
</div>
</body>
<- script written here ->
**HTML**
欢迎来到
温度为:
脚本1
<script type="text/javascript" src="../node_modules/ejs/ejs.min.js"> </script>
<script src="//cdnjs.cloudfare.com/ajax/libs/jquery/2.1.3/jquery.min.js">
<script>
$('#distTxt').on('click',function(){ //some code which is not getting called});
</script>
$('#distTxt')。on('click',function(){//一些未被调用的代码});
问题:这不起作用,因为浏览器显示未定义$in的错误
脚本2
Even when i bind onclick listener to the button:
<input type="button" id="getDistance" value="Get Distance" onclick="getDis();">
<script>
function getDis(){
//ajax send request
console.log('not working');
}
</script>
即使我将onclick listener绑定到按钮:
函数getDis(){
//ajax发送请求
console.log(“不工作”);
}
这个简单的onclick也不起作用。
我有没有错过一些非常基本的东西
问题2。在ejs中使用ajax调用有一种优雅的方式吗
问题3。为什么jQuery不能与EJS一起工作 请尝试使用jQuery('#distTxt')而不是$,看看这是否有效。我只是想缩小范围。你说得对,使用$symbol时存在一些内部冲突。谢谢