1

以下のスクリプトをjsfiddleでテストしましたが、正常に動作します。誰かが修正方法を教えてくれますか?これは私が作業する必要のあるURLです。右上のウィザードスタイルメニューでは、クリックすると各アイテムがアクティブに設定され、別のメニューアイテムがクリックされると削除されるはずです:http://morxmedia.com/clients/temp /45p/index_vertical.html

これに私が使用しているコードは次のとおりです。

    <script type="text/javascript">
      $('.wizard-steps div').click(function(e) {
            e.preventDefault();
            $('a').removeClass('active');
            $(this).addClass('active');
        });
    </script>
4

5 に答える 5

3

クリックイベントを要素にバインドするのは、そのような要素divにバインドする必要がある場合です。a

$(document).ready(function(){
    $('.wizard-steps > div > a').click(function(e) {
        e.preventDefault();
        $('a').removeClass('active');
        $(this).addClass('active');
    });
});
于 2012-06-27T08:42:21.267 に答える
2

これを試して。

$(function() {
    $('.wizard-steps div').click(function(e) {
       e.preventDefault();
       $(this).addClass('active').siblings().removeClass('active');
    });
});
于 2012-06-27T08:47:34.157 に答える
1

準備ができてそれを含める方が良い

$(document).ready(function() {
  $('.wizard-steps div').click(function(e) {
        e.preventDefault();
        $('a').removeClass('active');
        $(this).addClass('active');
    });
});
于 2012-06-27T08:42:52.400 に答える
1

私が見る限り(あなたのCSSで)。クラスは、 -tagのactive下のdivwizard-stepsと親に移動する必要があります。a

これを試して:

<script type="text/javascript">
$('.wizard-steps div a').click(function(e) {
    if (e.preventDefault)
        e.preventDefault();
    else
        e.stop();

    $('.wizard-steps div').removeClass('active');
    $(this).parent().addClass('active');
});
</script>
于 2012-06-27T08:44:33.307 に答える
0

jqueryを使用して別の方法で行うことができます.not()

Jqueryコード:

$('.wizard-steps div').click(function() {
          $('.wizard-steps div').not(this).removeClass('active');
          $(this).addClass('active');
});

デモ: http: //jsfiddle.net/surendraVsingh/PLbbr/

于 2012-06-27T09:09:20.790 に答える