亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 javascipt 在函數內部使用函數?

如何使用 javascipt 在函數內部使用函數?

蕭十郎 2023-09-11 16:19:54
我目前正在嘗試為老師構建一個測驗模板,以供學生回答問題。我有一個 javascript 函數來顯示所需數量的問題,一個 html div 包含所有必要的輸入框,以及一個 javascript 函數來切換此 div。我的問題是我不知道如何將它們放在一起。這是我到目前為止所擁有的,我不知道為什么它不起作用。var wrapper = document.getElementById("myHTMLWrapper");var number = prompt("Enter the number of questions");var myHTML = '';for (var i = 0; i < number; i++) {  myHTML += '<span class="test">Question ' + (i + 1) +  '</span><br/><br/>'  <input type="button" value="Show DIV" id="bt" onclick="toggle(cont)">}wrapper.innerHTML = myHTMLfunction toggle(cont) {      var cont = document.getElementById('cont');      if (cont.style.display == 'block') {          cont.style.display = 'none';          document.getElementById(ele.id).value = 'Show DIV';      }      else {          cont.style.display = 'block';          document.getElementById(ele.id).value = 'Hide DIV';      }  };<form id='namennumber' action="includes/dbquestions.php" method="post">  <label for="quizname"><b>Quiz name</b></label>  <input name="quizname" type="text" placeholder="Enter quizname" required>  <div id="myHTMLWrapper">  </div></form><div style="border:solid 1px #ddd; padding:10px; display:none;" id="cont">  <div id="questionform" class="modal">    <label for="question"><b>Enter a question</b></label>    <input name="question" type="text" placeholder="Enter a question" value="question" required>    <br>    <label for="answer1">Possible answer A</label>    <input type="text" name="answer1" placeholder="Enter a possible answer" value="answer1" required>    <br>    <label for="answer2">Possible answer B</label>    <input type="text" name="answer2" placeholder="Enter a possible answer" value="answer2" required>    <br>    <label for="answer3">Possible answer C</label>    <input type="text" name="answer3" placeholder="Enter a possible answer" value="answer3" required>    <br>    <label for="answer4">Possible answer D</label>    <input type="text" name="answer4" placeholder="Enter a possible answer" value="answer4" required>    <br>  </div></div>
查看完整描述

1 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

  • 嘗試在此處添加單引號:onclick="toggle('cont')"

  • 并在此處刪除單引號:var cont = document.getElementById(cont);

是的,這不是 js 代碼,

<input?type="button"?value="Show?DIV"?id="bt"?onclick="toggle(cont)">

使用類似的東西

myHTML?+=?'<input?type="button"?value="Show?DIV"?id="bt"?onclick="toggle(\'cont\')">';

循環之后。


查看完整回答
反對 回復 2023-09-11
  • 1 回答
  • 0 關注
  • 86 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號