我試圖通過 onclick 屬性從 html 按鈕調用 js 函數(shù)。我在哪里傳遞兩個字符串作為參數(shù)。我在參數(shù)部分中回顯了兩個 php 變量,這在邏輯上似乎是正確的,并且該函數(shù)也接受了這些參數(shù),但沒有發(fā)生任何事情。它給我的功能不是用按鈕 onclick error 定義的。下面是代碼:腳本功能<script> function displayCommentSection(var cs, var cb) { // alert("in"); // alert(cs+" "+cb); if (document.getElementById(cs).style.display == 'block') { document.getElementById(cs).style.display = 'none'; document.getElementById(cb).innerHTML = 'comment'; } else { document.getElementById(cs).style.display = 'block'; document.getElementById(cb).innerHTML = 'cancel'; } }</script><button class="btn btn-dark" id="commentBtn<?php echo $i;?>" onclick="displayCommentSection('commentSection<?php echo $i;?>','commentBtn<?php echo $i;?>')">Comment</button>
1 回答

慕哥9229398
TA貢獻1877條經(jīng)驗 獲得超6個贊
您需要從函數(shù)定義中刪除“var”
function displayCommentSection(cs,cb){
if(document.getElementById(cs).style.display=='block') {
document.getElementById(cs).style.display='none';
document.getElementById(cb).innerHTML='comment';
}
else
{
document.getElementById(cs).style.display='block';
document.getElementById(cb).innerHTML='cancel';
}
}
- 1 回答
- 0 關注
- 202 瀏覽
添加回答
舉報
0/150
提交
取消