我正在使用php生成一些具有其ID和应作为参数显示的文本ID的按钮。但是由于某种原因,函数调用似乎无法正常工作。


  while($ row = $ query-> fetch(PDO :: FETCH_BOTH))
    {
      $ reviewDoor = $ row [0];
      $ korteTekst = $ row [1];
      $ langeTekst = $ row [2];

echo "<article><h4>Review van $reviewDoor</h4>";
echo "<section>$korteTekst</section>";
if (!empty($langeTekst))
{
echo "<section id='LongReview$teller' class='LongReviews'>$langeTekst</section>";
echo "<button id='LeesMeerKnop$teller' class='LeesMeerKnoppen' onclick='readMoreLess(LeesMeerKnop$teller,LongReview$teller)'>Lees meer...</button>";
}
echo "</article>";
    $teller++;

  
  }


文件链接正在工作


<script src="script.js" type="text/javascript"></script>



这是我正在尝试调用的功能


  函数readMoreLess(knopId,tekst){
  
  var knop = getElementById(knopId);
        var review = getElementById(tekst);
  
  window.alert(“ hallo”);
  
  如果(knop.textContent ===“ Lees meer ...”)
        {
           knop.textContent =“ Minder tekst ...”;
           review.style.display =“ block”;
    }
         否则,如果(knop.textContent ===“ Minder tekst ...”)
        {
        knop.textContent =“ Lees meer ...”;
                review.style.display =“ none”;
        }
        }

最佳答案

看起来像函数调用中的params值缺少引号:

 echo "<button id='LeesMeerKnop$teller' class='LeesMeerKnoppen' onclick='readMoreLess(\"LeesMeerKnop$teller\",\"LongReview$teller\")'>Lees meer...</button>";

10-05 23:23