<img src="http://www.baidu.com/img/baidu_jgylogo3.gif" onload="alert(this.height)"> 我想把后面的onload="alert 改成一个文本框,文本框里面是这个this.height的值。请问可以吗?另外,如果有多个图片,能不能也能用?

解决方案 »

  1.   

    就是:
    <input type='text' name='s_height' value='this.height'>
      

  2.   


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    <style>
    </style>
    </head>
    <body>
    <p>
    <img src="http://www.baidu.com/img/baidu_jgylogo3.gif" />
    <input />
    </p>
    <p>
    <img src="http://avatar.profile.csdn.net/2/3/6/2_missccc.jpg" />
    <input />
    </p>
    <script>
    function $(el){
    return typeof el == 'string' ? document.getElementById(el) : el;
    }
    function $t(name, cot){
    cot = cot || document;
    return cot.getElementsByTagName(name);
    }
    var img = $t('img');
    for(var i = 0, len = img.length; i < len; i++){
    img[i].onload = function(){
    $t('input', this.parentNode)[0].value = '图片高度: '+this.offsetHeight;
    }
    }
    </script>
    </body>
    </html>楼主 试试
      

  3.   

    楼上高手,妙极了!谢谢。
    但是,还需要请教,如何给这个文本框增加 name='s_height' 
    不然无法提交到数据库。