Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
change javascript let by html click event
<%- include("partials/header") %>
<p> this is main page</p> 
  
<% let cpp= 6 %>
<%  for (let i=0;i<cpp;i++){ %>
<div class="card">
  <li><%= cards[i].name %></li>
  <li><%= cards[i].price %></li>
  <li><%= cards[i].title %></li>
  <li><%= cards[i].inStore %></li>
  <li><%= cards[i].code %></li>
</div>
<% } %>
<div>button id="next">load more</button></div>

<%- include("partials/footer") %>

how I can change let cpp=6 to cpp=12 on clicking button id="next"

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The array cards must come from the res.render statement in your Javascript file, because there is no let cards.

res.render("ejsfile", {cards: [...]});

So the solution is to put the cpp integer there as well and omit the let cpp = 6 statement:

res.render("ejsfile", {
  cards: [...],
  cpp: Number(req.query.cpp) || 6 // default value
});

Then the first 6 entries would be available at http://server/mainpage?cpp=6 (and also at http://server/mainpage, because 6 is the default value). And the "next" button must link to http://server/mainpage?cpp=12.

See the documentation for req.query.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda