javascript或jquery在不同的按钮单击上更改不同的图像

javascript或jquery在不同的按钮单击上更改不同的图像,javascript,jquery,html,css,Javascript,Jquery,Html,Css,当我点击一个按钮时,我有五个按钮。当我点击第二个按钮时,一个图像再次出现在div标签中。另一个图像应该用一个新的图像替换该图像,以此类推。我应该编写什么代码来实现它 请帮我做那件事。可能是javascript或jquery。我认为这与onclick事件有关。 <div class="imageSelector" /> $(".btnOne").on("click", function(){ $(".imageSelector").html("put h

当我点击一个按钮时,我有五个按钮。当我点击第二个按钮时,一个图像再次出现在div标签中。另一个图像应该用一个新的图像替换该图像,以此类推。我应该编写什么代码来实现它

请帮我做那件事。可能是javascript或jquery。我认为这与onclick事件有关。


         <div class="imageSelector" />


  $(".btnOne").on("click", function(){

  $(".imageSelector").html("put here the html code of the image")

  })


  $(".btnTwo").....
$(“.btnOne”)。在(“单击”,函数(){ $(“.imageSelector”).html(“将图像的html代码放在这里”) }) $(“.btnTwo”)。。。。。

$(“.btnOne”)。在(“单击”,函数(){
$(“.imageSelector”).html(“将图像的html代码放在这里”)
})
$(“.btnTwo”)。。。。。
简单如下

<script type="text/javascript">
    $(function(){

        $('button').on('click',function(e){
            e.preventDefault();

            var imgSRC = $(this).data('src');

            $('#image').html('<img src="'+imgSRC+'" alt="" />');
        });

    });
</script>

<button data-src="image1.jpg">One</button>
<button data-src="image1.jpg">Second</button>
<button data-src="image1.jpg">Third</button>
<button data-src="image1.jpg">Fourth</button>
<button data-src="image1.jpg">Fifth</button>

<div id="image"></div>

$(函数(){
$('button')。在('click')上,函数(e){
e、 预防默认值();
var imgSRC=$(this).data('src');
$('#image').html('');
});
});
一个
第二
第三
第四
第五

简单如下

<script type="text/javascript">
    $(function(){

        $('button').on('click',function(e){
            e.preventDefault();

            var imgSRC = $(this).data('src');

            $('#image').html('<img src="'+imgSRC+'" alt="" />');
        });

    });
</script>

<button data-src="image1.jpg">One</button>
<button data-src="image1.jpg">Second</button>
<button data-src="image1.jpg">Third</button>
<button data-src="image1.jpg">Fourth</button>
<button data-src="image1.jpg">Fifth</button>

<div id="image"></div>

$(函数(){
$('button')。在('click')上,函数(e){
e、 预防默认值();
var imgSRC=$(this).data('src');
$('#image').html('');
});
});
一个
第二
第三
第四
第五

默认情况下,OldImage值设置第一个图像url,在函数中,将出现新图像的NewImage url,这可能是按钮的id

var oldImage="img.png";
function ImageChange(NewImage)
{
    $("#divId").replace(oldImage,"newImage");
    oldImage=newImage;
}

OldImage值默认设置第一个图像url,在函数中,将出现新图像的NewImage url,这可能是按钮的id

var oldImage="img.png";
function ImageChange(NewImage)
{
    $("#divId").replace(oldImage,"newImage");
    oldImage=newImage;
}

是的,这正是我想要的。thanks@Dipesh Parmar@Phpdeveloper欢迎使用我应该使用的默认jquery文件。我用了1.9。1@PhpdeveloperjQuery1.9是您所需要的全部是的,这正是我想要的。thanks@Dipesh Parmar@Phpdeveloper欢迎使用我应该使用的默认jquery文件。我用了1.9。1@PhpdeveloperjQuery1.9是您所需要的全部。谢谢,这段代码也在工作fine@LxZvthanks这个代码也在工作fine@LxZv