簡體   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