我有有一個像數據 - 屬性一些圖片:使用與數據-id選擇一個變量屬性
<img id="popup" class="Absolute_Center is_Image" alt="Girl Popup" data-picture="">
<img src="https://s3-us-west-2.amazonaws.com/example.jpg" data-picture = "1">
<img src="https://s3-us-west-2.amazonaws.com/example2.jpg" data-picture = "2">
etc...
我想添加一個事件監聽器來檢索該系列中的下一張照片。我想我可以做到這一點:
var oimgPopup = document.getElementById("popup");
/* retrieve data-picture value of current image showing in the image popup */
var y = oimgPopup.dataset.picture;
var y = oimgPopup.dataset.picture;
y = y + 1;
// Prints out corect data-picture value + 1
var nextImage = document.querySelector('[data-picture =' + y + ']');
console.log(nextImage);
/* SyntaxError: An invalid or illegal string was specified
var nextImage = document.querySelector('[data-picture =' + y + ']'); */
,我將檢索該系列中的下一個圖像元素的對象,然後我將它插入到#mypopup圖像元素。但是,當我運行此操作時,我收到了非法的字符串消息。有誰知道如何將一個變量合併到querySelector屬性選擇器中?在此先感謝...
您忘記CL OSE自己的圖片廣告 – Neal