• 0
Sign in to follow this  
Thyago Barbosa

Adaptação pra usar meu javascript sem jquery/.js

Question

Gente, tenho o seguinte script que está fazendo cálculos, só que ele só funciona com o <script scr> do jquery 3.2.1 e eu quero tirar ele (porque onde pretendo usar não funciona nenhum arquivo .js online e também não quero ter que baixar o .js e instalar ele no arquivo)

Daí o que eu queria saber é, quais alterações eu preciso fazer pra que esse script funcione sem esse .js :/ se alguém souber como faço isso, por favor use o meu como exemplo pra fazer as alterações

<select class="qtd-parc" type="text" name="qtd-parc" />
    <option value="1" selected>1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
			<option value="8">8</option>
			<option value="9">9</option>
			<option value="10">10</option>
			<option value="11">11</option>
			<option value="12">12</option>
			<option value="13">13</option>
			<option value="14">14</option>
			<option value="15">15</option>
			<option value="16">16</option>
			<option value="17">17</option>
			<option value="18">18</option>
			<option value="19">19</option>
			<option value="20">20</option>
			<option value="21">21</option>
			<option value="22">22</option>
			<option value="23">23</option>
			<option value="24">24</option>
			<option value="25">25</option>
			<option value="26">26</option>
			<option value="27">27</option>
			<option value="28">28</option>
			<option value="29">29</option>
			<option value="30">30</option>
			<option value="31">31</option>
			<option value="32">32</option>
			<option value="33">33</option>
			<option value="34">34</option>
			<option value="35">35</option>
			<option value="36">36</option>
			<option value="37">37</option>
			<option value="38">38</option>
			<option value="39">39</option>
			<option value="40">40</option>
			<option value="41">41</option>
			<option value="42">42</option>
			<option value="43">43</option>
			<option value="44">44</option>
			<option value="45">45</option>
			<option value="46">46</option>
			<option value="47">47</option>
			<option value="48">48</option>
			<option value="49">49</option>
			<option value="50">50</option>
<input class="valr-parc" type="text" name="valr-parc" placeholder="0,00" />
<input class="total-parc" type="text" name="total-parc" readonly />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
  
$(document).ready(function(){
	var qtd_parc   = $(".qtd-parc");
    var valr_parc  = $(".valr-parc");
    var total_parc = $(".total-parc");
    var dif  = $(".diferenca");
    var avista     = $(".avista"); 
    var zerar = $(".zerar");
    
	valr_parc.on("keyup", function(){
    	$(this).val($(this).val().replace(/\D/g,'').replace(/[0-9]{12}/, "").replace(/(\d{1})(\d{1,2})$/, "$1,$2").replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.').replace(/^(\d)/g,"R$ $1")); 
		var nw_valr_parc = valr_parc.val().replace(/[^\d.,]/g, '').replace(".", "").replace(".", "").replace(".", "");
		var multiplica = qtd_parc.val() * nw_valr_parc.replace(",", ".");
			total_parc.val(multiplica.toFixed(2).replace(/\D/g,'').replace(/(\d{1})(\d{1,2})$/, "$1,$2").replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.').replace(/^(\d)/g,"R$ $1"));
	
    });
    
	qtd_parc.on("change", function(){
    	$(this).val($(this).val().replace(/[^\d]/g, '')); 
		var nw_valr_parc = valr_parc.val().replace(/[^\d.,]/g, '').replace(".", "").replace(".", "").replace(".", "");
		var multiplica = qtd_parc.val() * nw_valr_parc.replace(",", ".");
			total_parc.val(multiplica.toFixed(2).replace(/\D/g,'').replace(/(\d{1})(\d{1,2})$/, "$1,$2").replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.').replace(/^(\d)/g,"R$ $1"));
    });
});
</script>

Script funcionando: https://jsfiddle.net/gtvzzvy5/

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this