繁体   English   中英

IE8 parseFloat问题

[英]IE8 parseFloat problem

在IE8中,出现以下错误:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; Tablet PC 2.0; .NET4.0C)
Timestamp: Mon, 11 Apr 2011 12:36:39 UTC


Message: Object doesn't support this property or method
Line: 102
Char: 4
Code: 0
URI: http://www.geoffmeierhans.com/js/jquery/appone.js

它所引用的行上具有以下代码:

var distance = parseFloat($('#distance').val());

有人知道为什么会这样吗?

谢谢

你可以试试这个吗?

$('#submit').click(function() {
  var mpg= $('#mpg').val();
  if(mpg=='') {
    alert("The average cannot be empty");
    $('#mpg').focus();
    return false; // cancel submission
  } 

  if (isNaN(mpg)) {
    alert("The value you entered is not a valid number");    
    $('#mpg').focus();
    return false; // cancel submission
  } 
  mpg = parseFloat(mpg);
  if (mpg==0) {
    alert("MPG cannot be 0"); // or you will divide by 0 later    
    $('#mpg').focus();
    return false; // cancel submission
  } 
  var distance = $('#distance').val();
  distance = isNaN(distance)? 0: parseFloat(distance);
  var costlitre = $('#costlitre').val()
  costlitre = isNaN(costlitre)?0: parseFloat(costlitre);

  // Work out litres needed
  if(symbol=='$') {
    gallons = distance / mpg;
    cost = gallons * costlitre
    cost = cost.toFixed(2);
  } else {
    gallons = distance / mpg;
    litresneeded = gallons * litres;
    cost = litresneeded * costlitre;
    cost = cost.toFixed(2);
  }
  $('#total').html(symbol+cost);
  $('#four').fadeOut("slow", function() {
    Cufon.replace('h1, p, .tip, #units, #price, #total', { color: '-linear-gradient(#fff, #fff)'});
    $('#five').fadeIn("slow");
  });
  return false; // cancel submission - change to true to submit
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM