< IMG>宽度高度 [英] <img> width height

查看:81
本文介绍了< IMG>宽度高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图能够操纵< img>的宽度和高度。但是好像没有b $ b。


是,我知道JavaScript会不操纵任何东西,这没关系。我

根本就不知道如何捕捉宽度或高度。一旦我能做到这一点,我就可以操纵它们。


这是< img>

<的HTML div class =" ImgMnp" ID = QUOT; myImg" onmouseover =" imgSize(''myImg'',''fpImg)">

< img src =" images / FirePlace.jpg"宽度= QUOT; 480"高度= QUOT; 640" ID = QUOT; fpImg" />

< / div>


这是我试图操纵< img>

函数的JavaScript imgSize(myID,myImg)

{

var myDiv = document.getElementById(myID); //得到正确< div>

var myImage = document.getElementById(myImg); //得到正确< img>

var myWidth = myImage.style.width; //尝试捕获< img>的宽度

var myHeight = myHeight.style.height; //尝试捕获< img>

alert(" myWidth +,+ myHeight")的高度; //显示我这个功能是否有效

}


有人请告诉我我做错了什么


-


Totus负鼠,总计Deum。

Totus ero,totum meum。

WSW

操纵< img>的宽度和高度但似乎没有。

是的,我知道JavaScript会不。操纵任何东西,这没关系。我根本不知道如何捕捉宽度或高度。一旦我能做到这一点,我就可以操纵它们。

这是< img>
< div class =" ImgMnp"的HTML。 ID = QUOT; myImg" onmouseover =" imgSize(''myImg'',''fpImg)">




此行中有一个语法错误,接近结尾。你是
错过了撇号。它应该去:


< div class =" ImgMnp" ID = QUOT; myImg" onmouseover =" imgSize(''myImg'',''fpImg'');">


我不知道这是不是破坏了代码的原因。


新闻aécrit:

我试图能够操纵< img>的宽度和高度但似乎没有能力。
< div class =" ImgMnp" ID = QUOT; myImg" onmouseover =" imgSize(''myImg'',''fpImg)">
< img src =" images / FirePlace.jpg"宽度= QUOT; 480"高度= QUOT; 640" ID = QUOT; fpImg" />
< / div>

以下是我试图操纵< img>
函数imgSize(myID,myImg)
{
var myDiv = document.getElementById(myID); //得到正确的< div>
var myImage = document.getElementById(myImg); //得到正确< img>
var myWidth = myImage.style.width; //尝试捕获< img>
var myHeight = myHeight.style.height的宽度; //尝试捕获< img>
警报的高度(" myWidth +,+ myHeight"); //显示我这个功能是否有效


有人请告诉我我做错了什么




最简单的方法:


< img src =" pict.jpg"

onmousover =" alert(''width =''+ this.width +''height =''+ this.height)" ;;>


也许你的代码会更好用:


var myWidth = myImage。风格和放大器;&放大器; myImage.style.width? myImage.style.width:

myImage.width; //尝试捕获< img>

var myWidth = myImage.style&& myImage.style.height的宽度? myImage.style.height:

myImage.height; //尝试捕捉< img>的高度

想法:

如果你的图像没有宽度或高度样式,你可以'抓住它。


-

Stephane Moriaux et son [moins] vieux Mac


test写道:

2006年4月21日星期五21:46:37 GMT,新闻写道:

我试图能够操纵宽度和/的高度
< img>但似乎不能。

是的,我知道JavaScript会不。操作任何东西,这没关系。
我根本不知道如何捕捉宽度或高度。一旦我能够这样做,我就可以操纵它们。

这是< img>
< div class =" ImgMnp"的HTML。 ID = QUOT; myImg" onmouseover =" imgSize(''myImg'',''fpImg)">



此行中有一个语法错误,接近结尾。你错过了撇号。它应该去:

< div class =" ImgMnp" id =" myImg"
onmouseover =" imgSize(''myImg'',''fpImg'');">

不知道那是什么意思虽然打破了密码。




我不知道我需要那个撇号谢谢。


Nope没有解决问题,如果我取出这两行


var myWidth = myImage.style.width;

var myHeight = myHeight.style.height;


功能正常,将它们放入功能崩溃中。

-


Totus负鼠,总计Deum。

Totus ero,totum meum。

WSW


I am trying to be able to manipulate the width and height of an <img> but do
not seem to be able.

"Yes", I know the JavaScript will "not" manip anything, which is ok. I
simply do not know how to capture the width or height. Once I can do that I
can manipulate them.

Here is the HTML for the <img>
<div class="ImgMnp" id="myImg" onmouseover="imgSize(''myImg'',''fpImg)">
<img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
</div>

Here is the JavaScript I tried to manipulate the <img>
function imgSize(myID,myImg)
{
var myDiv= document.getElementById(myID); //get correct <div>
var myImage=document.getElementById(myImg); //get correct <img>
var myWidth=myImage.style.width; //attempt to capture width of <img>
var myHeight=myHeight.style.height; //attempt to capture height of <img>
alert("myWidth+, +myHeight"); //show if I this function works
}

Will someone please tell me what I am doing wrong

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW

解决方案

On Fri, 21 Apr 2006 21:46:37 GMT, News wrote:

I am trying to be able to manipulate the width and height of an <img> but do
not seem to be able.

"Yes", I know the JavaScript will "not" manip anything, which is ok. I
simply do not know how to capture the width or height. Once I can do that I
can manipulate them.

Here is the HTML for the <img>
<div class="ImgMnp" id="myImg" onmouseover="imgSize(''myImg'',''fpImg)">



There is a syntax error in this line, near the end. You''re
missing an apostrophe. It should go:

<div class="ImgMnp" id="myImg" onmouseover="imgSize(''myImg'',''fpImg'');">

Don''t know if that was what was breaking the code though.


News a écrit :

I am trying to be able to manipulate the width and height of an <img> but do
not seem to be able. <div class="ImgMnp" id="myImg" onmouseover="imgSize(''myImg'',''fpImg)">
<img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
</div>

Here is the JavaScript I tried to manipulate the <img>
function imgSize(myID,myImg)
{
var myDiv= document.getElementById(myID); //get correct <div>
var myImage=document.getElementById(myImg); //get correct <img>
var myWidth=myImage.style.width; //attempt to capture width of <img>
var myHeight=myHeight.style.height; //attempt to capture height of <img>
alert("myWidth+, +myHeight"); //show if I this function works
}

Will someone please tell me what I am doing wrong



simplest way :

<img src="pict.jpg"
onmousover="alert(''width = ''+this.width+'' height = ''+this.height)";>

maybe your code would be better with :

var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
myImage.width; //attempt to capture width of <img>
var myWidth= myImage.style&&myImage.style.height? myImage.style.height :
myImage.height; //attempt to capture height of <img>

idea :
If your image didn''t get a width or height style, you can''t catch it.

--
Stephane Moriaux et son [moins] vieux Mac


test wrote:

On Fri, 21 Apr 2006 21:46:37 GMT, News wrote:

I am trying to be able to manipulate the width and height of an
<img> but do not seem to be able.

"Yes", I know the JavaScript will "not" manip anything, which is ok.
I simply do not know how to capture the width or height. Once I can
do that I can manipulate them.

Here is the HTML for the <img>
<div class="ImgMnp" id="myImg" onmouseover="imgSize(''myImg'',''fpImg)">



There is a syntax error in this line, near the end. You''re
missing an apostrophe. It should go:

<div class="ImgMnp" id="myImg"
onmouseover="imgSize(''myImg'',''fpImg'');">

Don''t know if that was what was breaking the code though.



I did not know I need that apostrophe thanks.

Nope did not correct the problem, if I take out these two lines

var myWidth=myImage.style.width;
var myHeight=myHeight.style.height;

the function works, put them in the function crashes.
--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW


这篇关于&LT; IMG&GT;宽度高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆