How to reload or give Refresh in CSS page with Javascript [closed]

3

I made a code that should generate multiple inputs :

var n = document.getElementById("numeroCamadas").value
    var ttt;

    var layers = {}
    for (var i =0; i<n; i++){

        layers["layer" + i] = { 
        'espessura':0 ,
        'altura':0 ,
        'pesoEspecifico':0,
        'tensaoHorizontal':0,
        'poroPressao':0,
        'tensaoTotal':0,
        'tensaoTotalMeio':0,
        'tensaoTotalEfetiva':0,
        'tensaoTotalEfetivaMeio':0};




        ttt +="<li class=\"ui-field-contain\">"

            +"<h5>Camada "+(i+1)+"</h5>"
            +"<div style=\"float:left; width:30%;\">"
            +"<input type=\"number\" placeholder=\"Altura"+(i+1) +"\" value=\"\" id=\"altura"+(i+1) +"\" onfocusout=\"tensao()\">"
            +"</div>"
            +"<div style=\"float:left; width:30%;\">"
            +"<input type=\"number\" placeholder=\"Peso Especifico"+(i+1) +"\" value=\"\" id=\"pesoEspecifico"+(i+1) +"\" onfocusout=\"tensao()\">"
            +"</div>"
            +"<div style=\"float:left; width:30%;\">"
            +"<input type=\"number\" placeholder=\"Tensão Horizontal"+(i+1) +"\" value=\"\" id=\"geraCamadasHorizontal"+(i+1) +"\" onfocusout=\"tensao()\">"
            +"</div>"
            +"<br>"
            +"<li>Espessura da Camada:<b id=\"espessuraCamada"+(i+1) +"\"></b></li>"
            +"<li>Tensão Total:<b id=\"uMedia\"></b></li>"
            +"<li>Tensão Efetiva:<b id=\"fc\"></b></li><br>"
            +"</li>"




    }


    document.getElementById("camadas").innerHTML=ttt
}

The code works, but everything it generates does not come with CSS, which is the CSS of jquery.mobile-1.4.5.min.css .

Is there any function to call CSS or something like that ???

I was advised to do this:

$(".ui-field-contain").css("border-bottom-width","1px");
$(".ui-field-contain").css("border-bottom-right-radius","inherit");
$(".ui-field-contain").css("border-bottom-left-radius","inherit");
$(".ui-field-contain").css("border-top-left-radius","inherit");
$(".ui-field-contain").css("padding","0.7em 1em");
$(".ui-field-contain").css("border-right-width","1px");
$(".ui-field-contain").css("border-left-width","1px");
$(".ui-field-contain").css("border-width","1px 0 0");
$(".ui-field-contain").css("border-style","solid");
$(".ui-field-contain").css("margin","0");
$(".ui-field-contain").css("display","block");
$(".ui-field-contain").css("position","relative");
$(".ui-field-contain").css("text-align","left");
$(".ui-field-contain").css("text-overflow","ellipsis");
$(".ui-field-contain").css("overflow","hidden");
$(".ui-field-contain").css("white-space","nowrap");
$(".ui-field-contain").css("background-color","white");
$(".ui-field-contain").css("border-color","#ddd");
$(".ui-field-contain").css("color","#333");
$(".ui-field-contain").css("text-shadow","0 1px 0 #f3f3f3");
$("input").css( "margin" , "0" );
$("input").css( "min-height" , "2.2em" );
$("input").css( "text-align" , "left" );
$("input").css( "border-radius" , "5px" );
$("input").css( "background" , "transparent none" );
$("input").css( "line-height" , "1.4em" );
$("input").css( "display" , "block" );
$("input").css( "width" , "auto" );
$("input").css( "box-sizing" , "border-box" );
$("input").css( "outline" , "0" );

$("input").css( "color" , "inherit" );
$("input").css( "text-shadow" , "inherit" );
$("input").css( "font-size" , "1em" );
$("input").css( "font-family" , "sans-serif" );

$("#cfc").css( "margin-left" , "5em" );

But it's a lot of work, and it's not giving a legal result.

Follow the index as requested            

Soil stresses

         Menu      
<div role="main" class="ui-content">

    <ul data-role="listview" data-inset="true">
        <li class="ui-field-contain">
            <label style="width:3em; float:left;">Número de Camadas</label> 
            <div style="float:right; width:30%;">
                <input type="number" value="2" id="numeroCamadas" onfocusout="()">
            <button onclick="geraCamadas()">Gerar Camadas</button>
            </div>

        </li>
    </ul>


    <ul data-role="listview" data-inset="true" id="camadas">
        <li class="ui-field-contain">
            <h5>Camada 1</h5>
            <div id="cfc" style="float:left; width:30%;">
                <input type="number" placeholder="Altura" value="" id="altura1" id="put" onfocusout="">
            </div>
            <div id="cfc" style="float:left; margin-left: 0.5em; width:30%;">
                <input type="number" placeholder="Peso Espeçifico" value="" id="PesoEspecifico1" onfocusout="tensao()">
            </div>
            <div id="cfc" style="float:left; margin-left: 0.5em; width:30%;">
                <input type="number" placeholder="Tensão Horizontal" value="" id="TensaoHorizontal" onfocusout="tensao()">
            </div><br>
        </li>




        <li>Umidade média:<b id="uMedia"></b></li>
        <li>Fator Correção:<b id="fc"></b></li>
    </ul>




</div>

<div data-role="footer">
    <h4>Page Footer</h4>



</div><!-- /footer -->
</body>
    
asked by anonymous 09.05.2015 / 19:36

3 answers

0

You can change css dynamically, it's not very conventional, but you can do something like:

function alterar(valor){
  switch(valor){
    case "1":
      document.getElementById("main-css").href = "http://templated.co/items/demos/retrospect/assets/css/main.css";
      break;
    case "2":
      document.getElementById("main-css").href = "http://templated.co/items/demos/typify/assets/css/main.css";
      break;
    case "3":
      document.getElementById("main-css").href = "https://jquerymobile.com/jquery-wp-content/themes/jquerymobile.com/style.css";
      break;
    case "4":
      document.getElementById("main-css").href = "";
      break;
    default:break;
  }
}
<link id="main-css" rel="stylesheet" href="https://jquerymobile.com/jquery-wp-content/themes/jquerymobile.com/style.css">

Alterar o tema: 
<select id="selecione" onchange="alterar(this.value)">
  <option value="1">retrospect</option>
  <option value="2">typify</option>
  <option value="3">jquery-mobile</option>
  <option value="4">default</option>
</select>

<div role="main" class="ui-content">
  <ul data-role="listview" data-inset="true">
    <li class="ui-field-contain">
      <label style="width:3em; float:left;">Número de Camadas</label>
      <div style="float:right; width:30%;">
        <input type="number" value="1" id="numeroCamadas" onfocusout="()">
        <button onclick="geraCamadas()">Gerar Camadas</button>
      </div>
    </li>
  </ul>
  <ul data-role="listview" data-inset="true" id="camadas">
    <li class="ui-field-contain">
      <h5>Camada 1</h5>

      <div id="cfc" style="float:left; width:30%;">
        <input type="number" placeholder="Altura" value="" id="altura1" id="put" onfocusout="">
      </div>
      <div id="cfc" style="float:left; margin-left: 0.5em; width:30%;">
        <input type="number" placeholder="Peso Espeçifico" value="" id="PesoEspecifico1" onfocusout="tensao()">
      </div>
      <div id="cfc" style="float:left; margin-left: 0.5em; width:30%;">
        <input type="number" placeholder="Tensão Horizontal" value="" id="TensaoHorizontal" onfocusout="tensao()">
      </div>
      <br>
    </li>
    <li>Umidade média:<b id="uMedia"></b>

    </li>
    <li>Fator Correção:<b id="fc"></b>

    </li>
  </ul>
</div>
<div data-role="footer">
  <h4>Page Footer</h4>
</div>
  

Obs : I do not know if it is good or bad to assign an id to a link element, but it is something that can be done.

Note that I am assigning a id to a link element, and I am changing the css template according to the user selected, if you want to call your css again, just add the document.getElementById("id_do_link").href = "caminho_do_seu_css.css"; line %

    
03.10.2015 / 06:45
0

After popularizing your layers, try calling .trigger('create') on it.

var tmplCamada = document.getElementById("tmplCamada").content;
var numeroCamadas = document.getElementById("numeroCamadas");
var geraCamadas = document.getElementById("geraCamadas");
var camadas = document.getElementById("camadas");

var onTensaoFocusOut = function (event) {

}

geraCamadas.addEventListener("click", function (event) {
  var limite = parseInt(numeroCamadas.value);
  var indice = 0;
  var layers = {}

  for (;indice < limite; indice++) {
    layers["layer" + indice] = { 
      'espessura':0 ,
      'altura':0 ,
      'pesoEspecifico':0,
      'tensaoHorizontal':0,
      'poroPressao':0,
      'tensaoTotal':0,
      'tensaoTotalMeio':0,
      'tensaoTotalEfetiva':0,
      'tensaoTotalEfetivaMeio':0
    };

    var camada = document.importNode(tmplCamada, true);
    var titulo = camada.querySelector("h5");
    var elementos = camada.querySelectorAll("[id]");

    titulo.textContent += (indice + 1);
    [].forEach.call(elementos, function (element) {
      element.id += (indice + 1);
      if (element.tagName == "INPUT") {
        element.placeholder += (indice + 1);
        element.addEventListener("focusout", onTensaoFocusOut);
      };    
    });

    camadas.appendChild(camada);
    
    //aqui está o pulo do gato!
    $(camadas).trigger("create");
  }
});
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script><scriptsrc="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>

<div data-role="page">
  <div data-role="header">
    <h1>Page Header</h1>
  </div>

  <div role="main" class="ui-content">
    <ul data-role="listview" data-inset="true">
      <li class="ui-field-contain">
        <label style="width:3em; float:left;">Número de Camadas</label> 
        <div style="float:right; width:30%;">
          <input type="number" value="2" id="numeroCamadas">
          <button id="geraCamadas">Gerar Camadas</button>
        </div>
      </li>
    </ul>
    <ul data-role="listview" data-inset="true" id="camadas">

    </ul>
  </div>
  <div data-role="footer">
    <h4>Page Footer</h4>
  </div>
</div>
<template id="tmplCamada">  
  <li class="ui-field-contain">

    <h5>Camada </h5>
    <div style="float:left; width:30%;">
      <input type="number" placeholder="Altura" value="" id="altura" />
    </div>
    <div style="float:left; width:30%;">
      <input type="number" placeholder="Peso Especifico" value="" id="pesoEspecifico" />
    </div>
    <div style="float:left; width:30%;">
      <input type="number" placeholder="Tensão Horizontal" value="" id="geraCamadasHorizontal" />
    </div>
    <br>
  </li>
  <li>Espessura da Camada:<b id="espessuraCamada"></b></li>
  <li>Tensão Total:<b id="uMedia"></b></li>
  <li>Tensão Efetiva:<b id="fc"></b></li><br>

</template>

Since I was not able to do jQuery Mobile on the Snippet here from SO-pt, then follow the same code above in JSFiddle

    
15.12.2015 / 13:01
0

After popularizing your layers, try calling .trigger('create') on it.

var tmplCamada = document.getElementById("tmplCamada").content;
var numeroCamadas = document.getElementById("numeroCamadas");
var geraCamadas = document.getElementById("geraCamadas");
var camadas = document.getElementById("camadas");
var layers = {};

var onTensaoFocusOut = function (event) {

}

geraCamadas.addEventListener("click", function (event) {
  var itens = camadas.querySelectorAll(".ui-field-contain");
  var limite = parseInt(numeroCamadas.value);
  var indice = itens.length;

  if (indice != limite) {
    if (indice < limite) {
      for (;indice < limite; indice++) {
        layers["layer" + indice] = { 
          'espessura':0 ,
          'altura':0 ,
          'pesoEspecifico':0,
          'tensaoHorizontal':0,
          'poroPressao':0,
          'tensaoTotal':0,
          'tensaoTotalMeio':0,
          'tensaoTotalEfetiva':0,
          'tensaoTotalEfetivaMeio':0
        };

        var camada = document.importNode(tmplCamada, true);
        var titulo = camada.querySelector("h5");
        var elementos = camada.querySelectorAll("[id]");

        titulo.textContent += (indice + 1);
        [].forEach.call(elementos, function (element) {
          element.id += (indice + 1);
          if (element.tagName == "INPUT") {
            element.placeholder += (indice + 1);
            element.addEventListener("focusout", onTensaoFocusOut);
          };    
        });
        camadas.appendChild(camada);
      }      
    } else {
      for (indice--;indice >= limite; indice--) {
        delete layers["layer" + indice];
        for (var prox = 0; prox <= 3;) {
          camadas.removeChild(itens[indice].nextSibling);
          if (itens[indice].nextSibling.nodeType == 1) {
            prox++
          }
        }
        camadas.removeChild(itens[indice]);
      }
    }
    //aqui está o pulo do gato!
    $(camadas).trigger("create");
  }
});
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script><scriptsrc="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>

<div data-role="page">
  <div data-role="header">
    <h1>Page Header</h1>
  </div>

  <div role="main" class="ui-content">
    <ul data-role="listview" data-inset="true">
      <li class="ui-field-contain">
        <label style="width:3em; float:left;">Número de Camadas</label> 
        <div style="float:right; width:30%;">
          <input type="number" value="2" id="numeroCamadas">
          <button id="geraCamadas">Gerar Camadas</button>
        </div>
      </li>
    </ul>
    <ul data-role="listview" data-inset="true" id="camadas">

    </ul>
  </div>
  <div data-role="footer">
    <h4>Page Footer</h4>
  </div>
</div>
<template id="tmplCamada">  
  <li class="ui-field-contain">

    <h5>Camada </h5>
    <div style="float:left; width:30%;">
      <input type="number" placeholder="Altura" value="" id="altura" />
    </div>
    <div style="float:left; width:30%;">
      <input type="number" placeholder="Peso Especifico" value="" id="pesoEspecifico" />
    </div>
    <div style="float:left; width:30%;">
      <input type="number" placeholder="Tensão Horizontal" value="" id="geraCamadasHorizontal" />
    </div>
    <br>
  </li>
  <li>Espessura da Camada:<b id="espessuraCamada"></b></li>
  <li>Tensão Total:<b id="uMedia"></b></li>
  <li>Tensão Efetiva:<b id="fc"></b></li><br>

</template>

Since I was not able to do jQuery Mobile on the Snippet here from SO-pt, then follow the same code above in JSFiddle

    
15.12.2015 / 13:23