Javascript 使用单击事件如何更改图像?
目标:单击红色方块时,蓝色方块应变为红色 我想知道当用户点击某个东西时,如何复制一个图像。当用户单击图像时,我需要在其他地方生成相同的图像。目前,这是我的代码,无法实现我的目标。(使用Jquery也很好) HTMLJavascript 使用单击事件如何更改图像?,javascript,jquery,html,Javascript,Jquery,Html,目标:单击红色方块时,蓝色方块应变为红色 我想知道当用户点击某个东西时,如何复制一个图像。当用户单击图像时,我需要在其他地方生成相同的图像。目前,这是我的代码,无法实现我的目标。(使用Jquery也很好) HTML 请更正您的代码: 函数changeImage(){ var imgSrc=http://placehold.it/150'; if(document.getElementById('myImage').src==imgSrc){ document.getElementById('n
请更正您的代码:
函数changeImage(){
var imgSrc=http://placehold.it/150';
if(document.getElementById('myImage').src==imgSrc){
document.getElementById('new').src=imgSrc;
}
}
请更正您的代码:
函数changeImage(){
var imgSrc=http://placehold.it/150';
if(document.getElementById('myImage').src==imgSrc){
document.getElementById('new').src=imgSrc;
}
}
这应该行得通
HTML
<img id="myImage" src="http://placehold.it/150">
<img id="new" src="http://placehold.it/200">
这应该行得通
HTML
<img id="myImage" src="http://placehold.it/150">
<img id="new" src="http://placehold.it/200">
尝试将
document.getElementById('myImage').src
为您提供的内容记录在控制台上。将document.getElementById('myImage').src
为您提供的内容记录在控制台上
<img id="myImage" src="http://placehold.it/150">
<img id="new" src="http://placehold.it/200">
$(function(){
$("#myImage").click(function() {
$("#new").attr("src","http://placehold.it/150")
});
});