-2

I'm new with javaScript and I'm having trouble with this mixed code segment that I got off a couple of sites.

<script type='text/javascript'>

var img = new Image();
img.onload = function() {
$("ph&W").text(this.width + 'x' + this.height);
}
img.src = ("#hi");

</script>

Could you please correct this code segment, i'm sure it will help others to come :) Thanks.

4

1 回答 1

2

Javascript:

var img = new Image();
img.onload = function() {
  $("#phW").html(this.width + 'x' + this.height);
}
img.src = ("http://www.google.com/images/logo.png");

HTML:

<p id="phW"></p>​

演示:http: //jsfiddle.net/LBkXA/

于 2013-01-03T11:30:33.997 回答