I want to set an image control with some url but the image should only shown to the user when it is fully loaded. Below is my code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<img id="1" />
<img id="2" />
</body>
<script type="text/javascript">
$("<img/>").attr("src", $("#1").attr("src"))
.load(function() {
//How to set image 2 with with image which I just loaded
});
</script>
</html>
Above I am loading the image of img1 in memory, now how I am going to set the same image to img2. I am loading image in memory of img1 because I want to show the img2 with img1 src at once.
First off, the HTML
idelement cannot start with a number, soid="1"is invalid (it may not work in every browser). I’d suggest using a common prefix (such asimg). Thus1would becomeimg1and2would becomeimg2.Second, inside of an event handler,
thisis set to the element that triggered the event, so:would work.