admin管理员组

文章数量:1432367

I have a page that - If demo.text is 'disabled' than disabled demo button else enabled demo button.

index.ejs

<% for(project of projects) { %>
   <a class="info" href="#"> 
<% if(project.demo == 'disabled') { %>
   <button class="btn btn-primary" disabled> Button1 </button>
<% } else { %>
  <button class="btn btn-primary"> Button1 </button>
 </a>
<% } %>`

app.js

app.get('/', (req, res) => {
res.render('index', {
    projects: [
        { demo: 'disabled' },
        { demo: '' }
    ]
  });
});

I have a page that - If demo.text is 'disabled' than disabled demo button else enabled demo button.

index.ejs

<% for(project of projects) { %>
   <a class="info" href="#"> 
<% if(project.demo == 'disabled') { %>
   <button class="btn btn-primary" disabled> Button1 </button>
<% } else { %>
  <button class="btn btn-primary"> Button1 </button>
 </a>
<% } %>`

app.js

app.get('/', (req, res) => {
res.render('index', {
    projects: [
        { demo: 'disabled' },
        { demo: '' }
    ]
  });
});
Share Improve this question asked Nov 27, 2017 at 10:40 Pradip DhakalPradip Dhakal 1,9621 gold badge14 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

while using EJS Template engine opening and closing should be correct. for further references http://ejs.co/#docs

 <% for(project of projects) { %>
      <a class="info" href="#"> 
         <% if(project.demo == 'disabled') { %>
              <button class="btn btn-primary" disabled> Button1 </button>
         <% } else { %>
             <button class="btn btn-primary"> Button1 </button>
         <% } %>
     </a>
<%}%>

本文标签: javascriptHow to use if statement in ejs with stringsStack Overflow