自已写的2个比较好的js

     function compute(rowIndex)
    {
        var price = document.getElementById('UnicPrice'+ rowIndex)
        var qty = document.getElementById('spanOrders_quantity'+ rowIndex)
  var total = document.getElementById('spanSubtotal'+ rowIndex)
  
  price.value = formatFloat(price.value)
  
  if(isNaN(qty.innerText))
  {
   ortotal = price.value * qty.textContent
   total.textContent = eval(ortotal).toFixed(2)
  }
  if(isNaN(qty.textContent))
        {
            ortotal = price.value * qty.innerText
   total.innerText = eval(ortotal).toFixed(2)
        }
  }

function formatFloat(src)
{
   var pointLength = ""+src.replace(/(/d*/.?)/,"").length

  if (src - parseInt(src) > 0 && pointLength > 2)
  {
   return ""+src.replace(/^(.*/..{2}).*$/,"$1")
  }
    return eval(src).toFixed(2);
}

 

    function compute1(rowIndex)
    {
        var price = document.getElementById('UnicPrice'+ rowIndex)
        var qty = document.getElementById('spanOrders_quantity'+ rowIndex)
  var total = document.getElementById('spanSubtotal'+ rowIndex)

  price.value = formatFloat(price.value)

  if(navigator.appName.indexOf("Explorer") > -1)
  {
            ortotal = price.value * qty.innerText
            total.innerText = eval(ortotal).toFixed(2)
        }
        else
        {
            ortotal = price.value * qty.textContent
            total.textContent = eval(ortotal).toFixed(2)
        }
  }

 

你可能感兴趣的:(自已写的2个比较好的js)