函数调用javascript无法正常工作

时间:2013-05-17 16:51:03

标签: php javascript html function

我正在使用php生成一些按钮,这些按钮的ID和文本的ID应该显示为参数。但由于某些原因,函数调用似乎不起作用。

  

而($行= $查询 - >取(PDO :: FETCH_BOTH))     {       $ reviewDoor = $行[0];       $ korteTekst = $行[1];       $ langeTekst = $行[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>

这是我试图调用的函数

  

function readMoreLess(knopId,tekst){

     

var knop = getElementById(knopId);
        var review = getElementById(tekst);

     

window.alert( “你好”);

     

if(knop.textContent ===“Lees meer ......”)
        {
           knop.textContent =“Minder tekst ......”;            review.style.display = “块”;     }
         否则if(knop.textContent ===“Minder tekst ...”)         {         knop.textContent =“Lees meer ......”;                 review.style.display = “无”;
        }         }

1 个答案:

答案 0 :(得分:3)

看起来在函数调用中对params值缺少引号:

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