我正在尝试组合下面的这两个 jQuery 函数,并能够为第一次单击第一行图像和第一次单击第二行图像添加 ID 属性。
这是jQuery代码:
$(".first-row, .second-row").on("click", "img", function() {
//want ID1 to be for the first click of first row of images
ID1 = $(this).attr('id');
//want ID2 to be for the first click of the second row of images
ID2 = $(this).attr('id');
console.log(ID + " " + ID2);
});
// desired outcome "individual yes" or "family maybe" ect ect
这是我的 HTML 代码:
<html>
<head>
<meta name="description" content="example of selection order" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title></title>
</head>
<body>
<div class="all-images">
<div class="first-row">
<div class="first-id">
<img src="image1.jpg" alt="Individual" id="individual">
</div>
<div class="second-em">
<img src="image2.jpg" alt="employer" id="employeer">
</div>
<div class="third-fa">
<img src="image3.jpg" alt="fam" id="family">
</div>
</div>
<div class="second-row">
<div class="yes-first">
<img src="image4.jpg" alt="yes" id="yes">
</div>
<div class="no-second">
<img src="image5.jpg" alt="no" id="yes">
</div>
<div class="maybe-third">
<img src="image6.jpg" alt="maybe" id="maybe">
</div>
</div>
</div>
</body>
</html>
就像我上面提到的,我只需要它来跟踪第一行图像的第一次点击和第二行图像的第一次点击的 ID 属性并将它们组合起来,然后将结果打印到控制台。