如果在普通页面 中:
function ppshow() {
for(i=0; i <document.getElementById( "sign ").getElementsByTagName( "img ").length;i++){
alert(document.getElementById( "sign ").getElementsByTagName( "img ")[i].width);
if(document.getElementById( "sign ").getElementsByTagName( "img ")[i].width> 100) {
document.getElementById( "sign ").getElementsByTagName( "img ")[i].width=100
} else {
document.getElementById( "sign ").getElementsByTagName( "img ")[i].width=document.getElementById( "sign ").getElementsByTagName( "img ")[i].width
} alert(bb.clientWidth);
}
加载页面时加载函数:
<body onload= "javascript:ppshow();>
<div id= "sign " runat= "server " <img src= 'http://tinyurl.com/2zo9on ' border=0 /> </div>
可以得到图片的宽度.
---------------------------
可我把他放在我的页面 中.不想写在body中,而且在repeater控件中.
<div id= "sign " name= "sign " runat= "server> <img id= "aaa " src= 'http://tinyurl.com/2zo9on '/> </div>
<script language= "javascript ">
for(i=0; i <document.body.all. <%=sign.ClientID.Replace( ": ", "_ ") %> .getElementsByTagName( "img ").length;i++){
alert(document.body.all. <%=sign.ClientID.Replace( ": ", "_ ") %> .getElementsByTagName( "img ")[i].height);
if(document.body.all. <%=sign.ClientID.Replace( ": ", "_ ") %> .getElementsByTagName( "img ")[i].width> 100) {
document.body.all. <%=sign.ClientID.Replace( ": ", "_ ") %> .getElementsByTagName( "img ")[i].width=100
} else {
document.body.all. <%=sign.ClientID.Replace( ": ", "_ ") %> .getElementsByTagName( "img ")[i].width=10
}}
</script>
这样我的不到图片的宽度.很急啊?谢谢了.
------解决方案--------------------------------------------------------
document.all.getElementsByID( " ")用这样
------解决方案--------------------------------------------------------
你知道“ <%=”是什么意思吗?