我错过了什么?点击按钮后,它会显示“您的测量结果为纳米”。 [英] What am I missing? Once clicking on the button it says "your measurement is nan"

查看:70
本文介绍了我错过了什么?点击按钮后,它会显示“您的测量结果为纳米”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>

   
      <meta charset="utf-8">
      <title> Currency Converter
      
         body { background-image: url("alien.png");}
         #converter { position: absolute; width: 300px; height: 200px; z-index: 15; top: 45%; left: 700px; margin: -100px 0 0 -150px;}
         #header { width:404px; border:5px solid black; border-radius:5px 5px 0px 0px; background-color: black; font-family: Courier; font-size: 150%; color: white;}
         #main_content { width:404px; border:5px solid black; border-radius:0px 0px 5px 5px; background-color: black; color: white; font-family: Courier;}
      
      
         function lengthConverter(valNum) {
         
         var length;
         
         length = document.getElementById('selLength').value;
         
         if (length=='cm') {
         valNum = valNum*2.54;
         }
         
         if (length=='ft') {
         valNum = valNum*0.0833;
         }
		 
         if (length=='yd') {
         valNum = valNum*0.02778;
         }
         
         valNum = valNum.toFixed(2);
         
         var resultsString = "<h2> Your measurement is "+ valNum +" </h2>";
         document.getElementById('results').innerHTML = resultsString;
         }
      
   
   
      <div id="converter">
         <div id="header"> Currency Converter</div> <!--End of header section -->
         <div id="main_content">
            
               <p>Please enter length in inches<br>
                  in.
               </p>
               <p>
                  Convert into<br>
                  
                     
                      Centimeters
                      Feet
                      Yards
                  
               </p>
               
            
            <div id="results"></div>
            <!-- End of results section-->
         </div>
         <!-- End of main content section-->
      </div>
      <!-- End of converter div section-->





我尝试了什么:



请帮助,我想在我的新大学为我复习,但我从来没有学过它在我以前的学校。



What I have tried:

Please help, this is suppose to be review for me at my new university but I never learned it at my previous school.

推荐答案

To quote Griff... We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.



然而,看起来你已经捅了一下它。缺少的是允许输入/选择数据的控件和用于触发函数执行计算的按钮等。不知道具体要求,这里有一个最基本形式的解决方案(没有任何样式)。




However, it looks like you have taken a stab at it. What is missing are controls to allow the input / selection of the data and a button or something to fire the function to perform the calculation. Not knowing the exact requirements, here is a solution in its most basic form (without any styling).

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
function lengthConverter(valNum) {

var length;

length = document.getElementById('selLength').value;

if (length=='cm') {
valNum = valNum*2.54;
}

if (length=='ft') {
valNum = valNum*0.0833;
}

if (length=='yd') {
valNum = valNum*0.02778;
}

valNum = valNum.toFixed(2);

var resultsString = "<h2> Your measurement is "+ valNum +" </h2>";
document.getElementById('results').innerHTML = resultsString;
}
	
</script>

<html>
<body>
 
  Value: <input type="text" id="valueToConvert" size="8" >inches<br/>
<input type="button" value="Convert To" onclick="var val=document.getElementById('valueToConvert').value;lengthConverter(val)">
   <select id="selLength">
  <option value="cm">Centimeter</option>
  <option value="ft">Foot</option>
  <option value="yd">Yard</option>
</select>
<div id="results">
</div>

</body>
</html> 





祝你在课程中好运,并且编码愉快。由于您是CP的新手,如果适合您,请接受解决方案/投票。



Good luck to you in your course, and happy coding. Since you are new to CP, please accept solution / vote up if it works for you.


这篇关于我错过了什么?点击按钮后,它会显示“您的测量结果为纳米”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆