Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

  • 0
Luís HNrique

Como funcionaria o localStorage em um codigo que cria tags?

Pergunta

Eu criei uma table que adiciona tr's e td's com uma função e preciso que ele salve e carregue os dados no locasStorage. Então como funcionaria o localStorage para salvar e carregar dados no script abaixo?

<!DOCTYPE html>
<html>
<head>
<style>
th{
color: white;
}

#block{
background-color: yellow;
}

table{
background-color: black;
}

td {
    border: 1px solid black;
    background-color: white;
}
</style>
</head>
<body>


<div style="position: absolute; bottom: 5px;">
<table id="myTable">
  <tr>
    <th>Id</th>
	<th>Nome</th>
    <th>Entradas</th>
    <th>Link</th>
  </tr>
  <tr> <td>1</td>
    <td>
    <a id="defaultName" href="" target="_blank">Nome do site</a><br>
    <input id="defaultInputName" placeholder="name here">
    </td>

    <td>
    <button onclick="defaultMinus()">&#8722;</button>
    <font id="defaultEpisode">0</font>
    <button onclick="defaultPlus()">+</button>
    </td>

    <td>
    <input id="defaultLinkInput" placeholder="link here">
    <button onclick="defaultSubmit()">submit</button>
    </td>
    
    <td>
    <button id="block">&#x1f512;</button>
    </td>
  </tr>
</table>


<button onclick="myCreateFunction()">+</button>
</div>



<script>
var rowNumber = 0;
var trCount = 1;

/////////////////////////////////////////////////////////////////////DEFAULT EPISODE FUNCTIONS
function defaultMinus(){
var test = document.getElementById("defaultEpisode").innerHTML --;
}

function defaultPlus(){
document.getElementById("defaultEpisode").innerHTML ++;
}
/////////////////////////////////////////////////////////////////////DEFAULT EPISODE FUNCTIONS
/////////////////////////////////////////////////////////////////////DEFAULT NAME-LINK FUNCTIONS
function defaultSubmit(){
if(document.getElementById("defaultInputName").value !== "" || document.getElementById("defaultLinkInput").value !== ""){
document.getElementById("defaultName").innerHTML = document.getElementById("defaultInputName").value;
document.getElementById("defaultName").href = document.getElementById("defaultLinkInput").value;
 document.getElementById("defaultLinkInput").value = "";
  document.getElementById("defaultInputName").value = "";
}
}
/////////////////////////////////////////////////////////////////////DEFAULT NAME-LINK FUNCTIONS

function myCreateFunction() {
rowNumber ++;
trCount ++;
    var table = document.getElementById("myTable");
    var row = table.insertRow(-1);
	row.id = "createdRow"+trCount;
	var rr = row.insertCell(0);
    var cell1 = row.insertCell(1);
    var cell2 = row.insertCell(2);
    var c = row.insertCell(3);
    var d = row.insertCell(4);
	d.id = "createdCell"+trCount;
    
	rr.innerHTML = trCount;
	
    cell1.innerHTML = '<a id="createdName'+trCount+'" href="" target="_blank">Nome do site'+trCount+';</a><br><input id="createdInputName'+trCount+'" placeholder="name here">';
    
    cell2.innerHTML = '<button id="createdMinusButton'+trCount+'" onclick="createdMinusfnc(this.id)">&#8722;</button><font id="createdNumber'+trCount+'"> 0 </font><button id="createdPlusButton'+trCount+'" onclick="createdPlusfnc(this.id)">+</button>';
    
    c.innerHTML = '<input id="createdInputLink'+trCount+'" placeholder="link here"> <button id="createdSubmitButton'+trCount+'" onclick="createdSubmitfnc(this.id)">submit</button>';
    
    d.innerHTML = '<button id="createdCloseButton'+trCount+'" onclick="createdClosefnc(this.id)" style="background-color: red;"> &#8722 </button>';
}


function createdMinusfnc(clicked_id){
document.getElementById("createdNumber"+clicked_id.substring(18).trim()).innerHTML --;
}

function createdPlusfnc(clicked_id){
document.getElementById("createdNumber"+clicked_id.substring(17).trim()).innerHTML ++;
}

function createdSubmitfnc(clicked_id){
	if(document.getElementById("createdInputName"+clicked_id.substring(19).trim()).value !== "" || document.getElementById("createdInputLink"+clicked_id.substring(19).trim()).value !== ""){
document.getElementById("createdName"+clicked_id.substring(19).trim()).innerHTML = document.getElementById("createdInputName"+clicked_id.substring(19).trim()).value 
document.getElementById("createdName"+clicked_id.substring(19).trim()).href = document.getElementById("createdInputLink"+clicked_id.substring(19).trim()).value  

document.getElementById("createdInputLink"+clicked_id.substring(19).trim()).value = "";
document.getElementById("createdInputName"+clicked_id.substring(19).trim()).value = "";
}
}



function createdClosefnc(clicked_id) /////////////PARTE DO GET CLICKED ID
{
var deleteThis = document.getElementById("createdCell"+clicked_id.substring(18).trim()).parentNode;
deleteThis.outerHTML = "";
delete deleteThis;
}

</script>



<button id="1" onClick="reply_click(this.id)">B1</button>
<button id="2" onClick="reply_click(this.id)">B2</button>
<button id="3" onClick="reply_click(this.id)">B3</button>

<script type="text/javascript">
function reply_click(clicked_id) /////////////PARTE DO GET CLICKED ID
{
    alert(clicked_id);
}
</script>
</body>
</html>

e carregar os dados no codigo abaixo?

Compartilhar este post


Link para o post
Compartilhar em outros sites

0 respostas a esta questão

Recommended Posts

Até agora não há respostas para essa pergunta


  • Conteúdo Similar

    • Por Rafael_Ferreira
      Não consigo carregar a imagem do captcha do meu formulário. Foi testado com o xampp e easyphp. Também não carregou a imagem de outros captcha. 
       
       
    • Por luiz monteiro
      Olá.
      Estou atualizando meu conhecimento com Front-End e me deparei com o seguinte problema.
      Criei um sistema para fazer o upload de imagens e alguns campos text.
      Algo bem simples para depois começar a estudar javascript para mostrar a miniatura....
      Mas quando saio do navegador Chrome ou da aba por mais de 3 minutos, ao retornar o navegador as vezes atualiza ou nem chega atualizar mas limpa os campos.
      Estou usando um Smart Motorola com Android, mas um amigo testou no iPhone e acontece a mesma coisa.
      Gostaria de saber se há como usar javascript para evitar isso?
      Agradeço desde já.

      <!DOCTYPE html>
      <html>
      <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <title>Uploader</title>
      </head>
      <body>
          <form action="?" method="post" enctype="multipart/form-data">
              <br><br>
              <div>selecione a imagem 1</div>
              <input type="file" name="foto1" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem1">
              
              <br><br>
              <input type="file" name="foto2" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem2">
              
              <br><br>

              <input type="file" name="foto3" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem3">
              
              <br><br>
              <input type="submit" value="Enviar">
              <br><br>
          </form>
      <?php
      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
          vardump ($_FILES);
      }
      ?>
      </body>
      </html>
       
       
       
    • Por belann
      Olá!
       
      Estou usando o nextjs versão 15.2.3 e criei uma navbar que quando é carregado o programa aparece com a home, mas na hora de clicar na página produtos desaparece a navbar.
      A navbar esta sendo chamada no layout.tsx estou usando typescript
      e fica dessa forma
      <div>           <Navbar/>             <main>{children}</main>             </div>  
    • Por ILR master
      Fala pessoal, tudo bem?
       
      Eu tenho o seguinte código:
       
      <script>
         $(function(){
      var jElement = $('.fixar_banner');
      $(window).scroll(function(){
          if ( $(this).scrollTop() > 120 ){
              jElement.css({
                  'position':'fixed',
                  'top':'10px'
              });
          }else{
              jElement.css({
                  'position':'relative',
                  'top':'auto'
              });
          }
      });
      });
      </script>
       
      Porém, eu quero que a div fique fixa até que outro elemento apareça na tela, tipo o rodapé da página por exemplo. É mais ou menos como a página de notícia do uol.
      https://noticias.uol.com.br/internacional/ultimas-noticias/2025/01/19/sonho-americano-brasileiros-moram-em-carro-e-buscam-comida-no-lixo-nos-eua.htm
       
      Espero ter sido claro.
       
      Obrigado :)
       
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.