Javascript Can';无法获取ejs文件

Javascript Can';无法获取ejs文件,javascript,node.js,express,ejs,Javascript,Node.js,Express,Ejs,我需要在另一个ejs文件中调用一个ejs文件,并且完全在函数中,但我始终“无法获取文件” 如果我在函数外执行include文件,它会工作。 但是我需要在函数中调用这个ejs文件 <input type = "submit" value = "heure" id="sub" style="width:120px" onclick="changer()"/> <input type = "submit" value = "journée" id="sub1" style="wid

我需要在另一个ejs文件中调用一个ejs文件,并且完全在函数中,但我始终“无法获取文件” 如果我在函数外执行include文件,它会工作。 但是我需要在函数中调用这个ejs文件

<input type = "submit" value = "heure"  id="sub" style="width:120px" onclick="changer()"/>
<input type = "submit" value = "journée" id="sub1" style="width:120px" onclick="changersub1()"/>

 <script type="text/javascript">
    function changersub1()
    {
         document.getElementById("sub1").style.backgroundColor="MistyRose";

         document.getElementById("sub").style.backgroundColor="white";

         window.location = "./index1.ejs";
    } 
 </script>

函数转换器sub1()
{
document.getElementById(“sub1”).style.backgroundColor=“MistyRose”;
document.getElementById(“sub”).style.backgroundColor=“白色”;
window.location=“./index1.ejs”;
} 

你有什么想法吗?用下面这句话谢谢你

window.location = "./index1.ejs";
您试图调用类似于localhost:5000/index1.ejs的东西,这是错误的Index1.ejs是一个模板文件,需要在服务器端呈现,如ExpressJS

router.get('/index1', function(request, response) {
   response.render('index1.ejs');
}); 
将上面的行添加到路线中,并将功能更改为以下

window.location = "/index1";

您不能直接从客户端访问ejs文件。您需要创建一个路由来呈现
index1.ejs
,然后将其添加到客户端
window.location=“/route url”