English 中文(简体)
在图像点上添加类别?
原标题:Adding class on an image click?
function updateOption(selection, option) {
        jQuery( body,html ).animate({
            scrollTop: jQuery("#msg").offset().top
        }, 800);
        jQuery( . +selection).each(function() {
            jQuery("img."+selection).removeClass("optionSelected");
        });
        jQuery.ajax({
            type: "GET",
            url: "../v1_include/v1_session_boutique.inc.php",
            data: selection + "=" + option,
            success: function(msg){
                jQuery( #msg ).fadeIn( fast );
                var List = document.getElementById( msg );
                List.innerHTML = msg;
                  jQuery(".StoreMsgPanier").animate( { opacity: 0.25 }, 1000)
                    .animate( { opacity: 1 }, 1000);
            }
        });
}


<p>Option 1</p>
<div id="opt3">
    <a href="javascript:updateOption( select_1_3 , 1-5-1 );"><img src="../v1_images_option/crop/5_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_3 optionSelected" /></a>
    <a href="javascript:updateOption( select_1_3 , 1-6-1 );"><img src="../v1_images_option/crop/6_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_3" /></a>
</div>
<p>Option 2</p>
<div id="opt2">
    <a href="javascript:updateOption( select_1_2 , 1-3-1 );"><img src="../v1_images_option/crop/3_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_2" /></a>
    <a href="javascript:updateOption( select_1_2 , 1-4-1 );"><img src="../v1_images_option/crop/4_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_2" /></a>
</div>

该法典做了一些细微的工作,但是,在取消所有选修课后,我如何能够在我刚刚点击的<<>/strong>的图像中增加选修课程?

感谢您的帮助......

最佳回答

您也可从打电话者处通过this,并在该职能范围内加以使用。

http://www.ohchr.org。 http://www.un.org/Depts/DGACM/index_french.htm

    <a href="javascript:updateOption( select_1_3 , 1-5-1 , this);">

www.un.org/Depts/DGACM/index_french.htm 改为_this.find()。

  function updateOption(selection, option, _this) {
    //..
    //...
       $(_this).parent().find("img").removeClass("optionSelected"); //remove class for all images
       $(_this).find("img").addClass("optionSelected"); //add class to the image inside the link

或者, 采用不妥协的方式是良好做法。 见下文。

http://www.ohchr.org。 http://www.un.org/Depts/DGACM/index_french.htm

<p>Option 1</p>
<div id="opt3">
    <a href="javascript: void(0)" data-opt="1-5-1" data-sel="select_1_3"><img src="../v1_images_option/crop/5_1.jpg" alt="Image" class="select_1_3 img_style optionSelected" /></a>
    <a href="javascript: void(0);" data-opt="1-6-1" data-sel="select_1_3"><img src="../v1_images_option/crop/6_1.jpg" alt="Image" class="select_1_3 img_style" /></a>
</div>
<p>Option 2</p>
<div id="opt2">
    <a href="javascript: void(0)" data-opt="1-3-1" data-sel="select_1_2"><img src="../v1_images_option/crop/3_1.jpg" alt="Image" class="select_1_2 img_style" /></a>
    <a href="javascript: void(0)" data-opt="1-4-1" data-sel="select_1_2"><img src="../v1_images_option/crop/4_1.jpg" alt="Image" class="select_1_2 img_style" /></a>
</div>

<>CSS:

.img_style { margin:2px;padding:5px;border:1px solid #D6D6D6; }

www.un.org/spanish/ecosoc 最后,联合材料:。 请作改动后在您执行之前加以理解。

$(function() {
    $( .img_style ).click(function() {
        $( body,html ).animate({
            scrollTop: $("#msg").offset().top
        }, 800);

        var $this = $(this);        

        $this //current link
        .closest( div ) //will return you the enclosing div lets say <div id="opt2">
        .find( img ) //find all images inside <div id="opt2">
        .removeClass("optionSelected"); //remove class

        $this.addClass( optionSelected );

        var $parent = $this.parent();

        var option = $parent.attr( data-opt ); //will return you the option
        var selection = $parent.attr( data-sel );

        $.ajax({
            type: "GET",
            url: "../v1_include/v1_session_boutique.inc.php",
            data: selection + "=" + option,
            success: function(msg) {
                $( #msg ).fadeIn( fast ).html(msg);

                $(".StoreMsgPanier").animate({
                    opacity: 0.25
                }, 1000).animate({
                    opacity: 1
                }, 1000);
            }
        });
    });
});

>DEMO/strong> -> 显示选择和选择可检索。

问题回答
$( #id_of_image ).on( click , function() {
  $( img ).removeClass( optionSelected );
  $(this).addClass( optionSelected );
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...