search

Home  >  Q&A  >  body text

javascript - for rounding problem

function integer_methods(){
    var aArray=document.getElementById('wang').getElementsByTagName("em");
    for(var i = 0;i < aArray.length; i++) {
        aArray[i].toFixed(0);   //提示出错 TypeError: aArray[i].toFixed is not a function
    }
}

I want to round the contents of all em tags under ID wang

phpcn_u1582phpcn_u15822744 days ago454

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:47:55

    Number(aArray[i])
    

    toFixed 函数是 Number 的方法。而 aArray[i] 的类型是 HTMLElement

    reply
    0
  • Cancelreply