本文介绍了无法对文档执行 querySelectorAll.怎么修?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么:

我有从 PHP 数组生成的链接,该数组生成自己的唯一 ID,该 ID 应指向它自己的模式(弹出窗口)div,该 div 具有与链接 ID 匹配的 ID.模态也是使用 PHP 数组自动生成的.我收到这个错误,我非常不熟悉(菜鸟).不知道如何修复.模态不起作用,我正在使用 Foundation 5 的显示插件.

I have links generated from a PHP array which produce it's own unique ID which should point to it's own modal (popup window) div which has a matching ID to the link ID. The modals are also auto generated using a PHP array. I am receiving this error, which I am very unfamiliar with (noob). Not sure how to fix. The modal isn't working and I am using Foundation 5's reveal plugin.

PHP 链接数组:

          //more code above

              if ($track->lyrics != null) { // If lyrics field isn't empty
                  $html .= '<a href="#" class="lyricCLicked" data-reveal-id="' . $track->id . '">Lyrics</a>';
                  $numTracksContainingLyrics++;
                  foreach ($track as $value) {
                     $lyricsArray[$track->id] = $track->lyrics;
                   }
        }

模态 DIV 数组

foreach ($lyricsArray as $key => $value) {
$lyricModal = '<div id="' . $key .'" class="reveal-modal" data-reveal>';
$lyricModal .= $value;
$lyricModal .= '<a class="close-reveal-modal">&#215;</a>';
$lyricModal .= '</div>';

echo $lyricModal;

}

结果正在写入 HTML 源代码.因此,数组正在工作和生成.它只是给了我这个在文档上执行 querySelectorALl 失败:#1042 不是一个有效的选择器.顺便说一句,1042"是正在生成的唯一 ID 之一如果你想知道.

The Results are being written to HTML source. So, the arrays are working and generating. It's just giving me this "Failed to Execute querySelectorALl on Document : #1042 is not a valid selector. By the way, "1042" is one of the unique IDs being generated in case you were wondering.

推荐答案

querySelectorAll 不喜欢只有数字(或前导数字)的 ID.这里有一个讨论.如果可能,我会在数字前加一些字母.

querySelectorAll doesn't like number-only (or leading-digit) ids. There is a discussion here. If possible, I would add some letters in front of the numbers.

这篇关于无法对文档执行 querySelectorAll.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:46