How can I use an image map to show/hide a particular div?

后端 未结 2 1663
礼貌的吻别
礼貌的吻别 2021-01-16 05:10

I have an image map and would like to be able to show/hide a div based on which item in the image map I click?

html...



        
2条回答
  •  别那么骄傲
    2021-01-16 05:32

    A similar answer was posted by someone else. I'm not sure why it was deleted. It appears to work:

    $('[item="texas"]')
    

    Here's an example:

    
    
    
        
        
     
    
    
    You clicked the Republic of Texas!
    You clicked Florida!
    $('[item="texas"]').click(function(){
        $(".display").hide();
        $("#texas").show();
        return false;
    });
    $('[item="florida"]').click(function(){
        $(".display").hide();
        $("#florida").show();
        return false;
    });
    

    http://jsfiddle.net/xtKXL/5/

    Edit:

    To make things a little more dynamic, you can grab the "item" from the over which you're hovering and use that value to display the appropriate

    :

    $('[item]').click(function(){
        var item=$(this).attr('item');
        $(".display").hide();
        $("#"+item).show();
        return false;
    });
    

    http://jsfiddle.net/xtKXL/6/

提交回复
热议问题