我需要在querySelectorAll()
中使用id作为变量,如下所示。
var thismodal = "myModal";
var clicked_id,trueModalId;
function openModal(clicked_id) {
trueModalId = thismodal + clicked_id;
document.getElementById(trueModalId).style.display = "block";
// var thisSlides = "mySlides" + clicked_id;
if($('trueModalId').find('.modal-content').length) {
alert(trueModalId);
}
}
function showSlides(){
var slides = document.querySelectorAll('trueModalId >.modal-content > .mySlides');
}
我如何进行这项工作?
答案 0 :(得分:0)
就像js中的每个变量和字符串连接一样。您忘记了#
作为ID的指示符
var trueModalId = "myModal";
var slides = document.querySelectorAll('#' + trueModalId + ' >.modal-content > .mySlides');