我试图隐藏并用js显示div并运行其他js

时间:2015-05-25 18:35:59

标签: javascript

Hy也许我弄得一团糟但我寻找选项女巫将会显示并隐藏结果calcres div。

基本上我坚持这个位置cus当我添加这个我的浏览器dosnt show calcres。



 <script> <!-- Kalkulator-->
 function mycalculator() {
        var a = parseInt(document.getElementById("a").innerHTML);
        var x = parseInt(document.getElementById("odrasli").value);
        var c = parseInt(document.getElementById("c").innerHTML);
        var y = parseInt(document.getElementById("deca").value);
        var aa = a * x;
        var cc = c * y;
        var p = aa + cc;
        var d = p * 0.2;
		document.getElementById("price").innerHTML = p;
        document.getElementById("depozit").innerHTML = d;
		
		}
		</script>
		<script><!-- hide div-->
	  function show() {
   document.getElementById('calcres').style.display = "block";
}
</script>
<script><!--js button to call both -->
function dugme() {
   mycalculator();
   show();
}
	  </script>
                
&#13;
<div class="calculator" style="position:left;"> <!--calculator test-->
<div id =a style='display:none;'><?php echo $Data->var_price1; ?></div>
<div id =c style='display:none;'><?php echo $Data->var_price2; ?></div>
 <input id="odrasli" type="number" placeholder="Number of Adults">
 <input id="deca" type="number" placeholder="Number of Children's">
 </br>
<button value="Submit" class="submite_btn" title="Submit" type="submit" onClick="dugme()"><span class="">Get Price</span></button>
<!-- <input type="button" class= "submite_btn" value="Get Price" onClick="mycalculator()">
-->
 <div class = "calcres" style="display:none;"">
 </br>
 Grand total</br>
 <div id="price"></div> <div class="dolar">$</div></br>
 Deposite </br>
 <div id="depozit"></div> <div class="dolar">$</div></br>
</div>
 </div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

<!-- Kalkulator-->标记内有<script>个,不确定它是否有效。我删除了那些,只是尝试下面的代码工作。

 <script type="text/javascript">

function mycalculator() {
        var a = parseInt(document.getElementById("a").innerHTML,10);
        var x = parseInt(document.getElementById("odrasli").value,10);
        var c = parseInt(document.getElementById("c").innerHTML,10);
        var y = parseInt(document.getElementById("deca").value,10);
        var aa = a * x;
        var cc = c * y;
        var p = aa + cc;
        var d = p * 0.2;
        document.getElementById("price").innerHTML = p;
        document.getElementById("depozit").innerHTML = d;

        }
function show() {
           document.getElementById('calcres').style.display = "block";
}

function dugme() {
   mycalculator();
   show();
}

</script>




<div class="calculator" style="position:left;"> <!--calculator test-->
<div id ="a" style='display:none;'>2</div>
<div id ="c" style='display:none;'>2</div>
 <input id="odrasli" type="number" placeholder="Number of Adults">
 <input id="deca" type="number" placeholder="Number of Children's">
 </br>
<button value="Submit" class="submite_btn" title="Submit" type="submit" onClick="dugme()"><span class="">Get Price</span></button>
<!-- <input type="button" class= "submite_btn" value="Get Price" onClick="mycalculator()">
-->
 <div id = "calcres" style="display:none;"">
 </br>
 Grand total</br>
    <div id="price"></div> <div class="dolar">$</div></br>
    Deposite </br>
     <div id="depozit"></div> <div class="dolar">$</div></br>
    </div>
 </div>

答案 1 :(得分:0)

您的代码有3个问题我必须告诉您:

  1. 您必须在JavaScript中使用//comment,而不是<!-- comment -->How to use Comment

  2. 您的<div id =a style='display:none;'>无效,应该是 <div id ='a' style='display:none;'>

  3. 换行符应该是<br><br />,而不是</br>HTML linebreak
  4. 示例:https://jsfiddle.net/v6nv4aag/2/

    另外,我认为在PHP中输出双引号时可能会遇到一些问题(link)