我有一個JS函數,該函數在單擊時調用,該函數傳遞一個字符串,并且第一個按鈕有效,但是所有后續按鈕都給我錯誤action is not a function (In 'action("upvote")', 'action' is "")其中 action 是函數的名稱,upvote 是傳遞的變量。使用檢查元素向我顯示兩個按鈕是相同的,這是它們的外觀<button type="button" onclick="action('upvote')">Like</button>最奇怪的是按鈕在它調用函數之前,并且適用于所有按鈕,而不僅僅是第一個按鈕<button type="button" onclick="fun(84)">Reply</button>我檢查了,我沒有忘記關閉任何div或按鈕我唯一能想到的是,我通過遞歸php函數來回顯這些,我不認為JS函數有范圍,但我不明白為什么第一個按鈕工作而不是后續如果需要更多代碼,請告訴我下面的代碼是我對父 divs 的打印函數 echo "<div class='parent' style='margin-left:".$width."px'>".$x['comment']." <div class='actions'> <button type='button' onclick='fun($ran)'>Reply</button> <button type='button' onclick='action(\"upvote\")'>Like</button> <button type='button'>Dislike</button>"; //Reply Like and Dislike are all actions every user gets, here I check which user it is to see if they can see the edit/delete //Normally I would check for admin rather than id == 2, but there is only 1 admin and he id 2 if(($comment['userid'] == $_SESSION['id']) || $_SESSION['id'] == 2){ echo "<button type='button'>Edit</button> <button type='button'>Delete</button></div>";//Close of actions div } else{ echo"</div>";//Close of actions div } $uname = mysqli_fetch_assoc($db->query("SELECT username FROM users WHERE id = ".$comment['userid']." ")); echo" <div class='info'> Score: ".$comment['score']." Posted By- ".$uname['username']."   At-".$x['created']." "; if($x['edited'] != NULL){ echo" Edited Last-".$x['edited']." </div>"; } else{ echo"</div>"; }?> </div> //Close of parent div這里仍然是我檢查注釋是否有任何回復注釋的函數的一部分,如果是這樣,我遞歸調用相同的函數,
Javascript 函數脫離了范圍?“X 不是函數” “X 是 ”“ ”
至尊寶的傳說
2022-08-04 16:53:37