的textbox里有一个事件getYinshua(this);他一开始是在onchange里
现在我想把他放在body的onlaod里,让这个页面一加载的时候就执行这个方法,但是出错了
原因是我的getYinshua(this);方法里有参数是动态的
我想让他加载的时候就能用该怎么办呢,求大神指点
方法如下:(错误就是id缺少对象)
function getYinshua(obj) {
        var pre=obj.id.split("_")[1];
        var ysling = Number(document.getElementById("dg2_" + pre + "_txt_ling").value); //张 色令  txt_ling
        var ysP = Number(document.getElementById("dg2_" + pre + "_txt_YsP").value); //张 色  txt_YsP
        var seling = Number(document.getElementById("dg2_" + pre + "_TextBox3").value);  //色令价  TextBox3
        var qibanfei = Number(document.getElementById("dg2_" + pre + "_TextBox7").value); //起版费 TextBox7
        var taoban = Number(document.getElementById("dg2_" + pre + "_txt_taoban").value); //套版 txt_taoban         var internalQiBanFei = Number(document.getElementById("dg2_" + pre + "_HidInternalQiBanFei").value); //内部起版费 HidInternalQiBanFei
        var internalSeLing = Number(document.getElementById("dg2_" + pre + "_HidInternalSeLing").value); //内部色令价 HidInternalSeLing
                 if (taoban == 0) {
                         document.getElementById("dg2_" + pre + "_HidPrintingDanXiang").value = 0; //印刷 内部单项费用
            document.getElementById("dg2_" + pre + "_TextBox2").value = 0;   //印刷 单项费用 TextBox2         } else {
            document.getElementById("dg2_" + pre + "_HidPrintingDanXiang").value = (Math.max(internalQiBanFei, ysling * ysP * internalSeLing)).toFixed(2); //印刷 内部单项费用  Add by Lebron in 2012-1-10
            document.getElementById("dg2_" + pre + "_TextBox2").value = (Math.max(qibanfei, ysling * ysP * seling)).toFixed(2);  //印刷 单项费用 TextBox2
        }
             }

解决方案 »

  1.   

    window.onload=function(){
         getYinshua(document.getElementById("文本域的ID"));
    }
    试试
      

  2.   


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    <style>
    </style>
    </head>
    <body>
    <select id="test">
    <option value="1">1-1</option>
    <option value="2">1-2</option>
    <option value="3">1-3</option>
    </select>
    <script>
    function $(el){
    return typeof el == 'string' ? document.getElementById(el) : el;
    }
    function test(o){
    alert( o.value )
    }
    $('test').onchange = function(){
    test(this);
    }
    window.onload = function(){
    $('test').onchange()
    }
    </script>
    </body>
    </html>
    楼主 是不是 类似这样的意思?
      

  3.   

    页面还没加载你就onload的了,obj还是空值,一进去就报空指针了
      

  4.   

    #3 
    不是的 ,我也试过window.onload 
    就是要解决加载的时候空指针的问题这个onload不是在页面加载完才执行的吗
      

  5.   

    把 this 换成 一变量

    window.onload=function(){
      getYinshua(document.getElementById("id").value);
    }
      

  6.   


    ++++
    document.getElementById 获取文本框对象