在使用div和next按钮后,我正在使用此代码重定向用户
但这对我不起作用:(

这是我的代码



$("a.xxx").click(function() {
  $(this).toggleClass("yyy").toggleClass("xxx");
});
$(".resellc").click(function() {
var rid = document.getElementsByTagName('yyy').id;
location.href = rid;
});

<a id="3" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">Apple watch</div></a><a id="18" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">Apple Watch</div></a><a id="21" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">BMW Bike</div></a><a id="30" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">Women lingerie</div></a>
<button class="resellc">next</button>





谢谢

最佳答案

您可以使用此:

$("a.xxx").click(function(e) {
    e.preventDefault();
    var rid = this.id;
    $(this).toggleClass("yyy").toggleClass("xxx");
    $(".resellc").off('click').one('click', function() {
        location.href = rid;
        console.log(rid);
    });
});




$("a.xxx").click(function(e) {
    e.preventDefault();
    var rid = this.id;
    $(this).toggleClass("yyy").toggleClass("xxx");
    $(".resellc").off('click').one('click', function() {
        location.href = rid;
        console.log(rid);
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="3" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">Apple watch</div></a><a id="18" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">Apple Watch</div></a><a id="21" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">BMW Bike</div></a><a id="30" class="xxx"><div style="color: black; padding: 10px; border-bottom: 0.1px solid;">Women lingerie</div></a>
<button class="resellc">next</button>

10-05 20:34