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

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

JavaScript:onClick 事件無需觸發即可工作

JavaScript:onClick 事件無需觸發即可工作

慕容708150 2021-12-12 09:38:25
我正在修改從互聯網上某處獲取的模板。到這里,分頁就完成了。最終頁面將提交表單。我試圖在不影響任何 CSS 的情況下修改它。所以我沒有將標簽更改為按鈕。我正在使用帶有 onClick 事件的錨標記,該事件將提交表單。但是 onClick 事件適用于頁面加載而不是 onClicking。function renderPagination(wizard, options, state) {  if (options.enablePagination) {    var pagination = "<{0} class=\"actions {1}\"><ul role=\"menu\" aria-label=\"{2}\">{3}</ul></{0}>",      buttonTemplate = "<li><a href=\"#{0}\" role=\"menuitem\">{1}</a></li>",      submitButtonTemplate = "<li><a href = \'#{0}\' onClick=" + document.getElementById('studentForm').submit() + " role=\"menuitem\">{1}</a></li>",      buttons = "";    if (!options.forceMoveForward) {      buttons += buttonTemplate.format("previous", options.labels.previous);    }    buttons += buttonTemplate.format("next", options.labels.next);    if (options.enableFinishButton) {      buttons += buttonTemplate.format("finish", options.labels.finish);    }    if (options.enableCancelButton) {      buttons += buttonTemplate.format("cancel", options.labels.cancel);    }    wizard.append(pagination.format(options.actionContainerTag, options.clearFixCssClass,      options.labels.pagination, buttons));    refreshPagination(wizard, options, state);    loadAsyncContent(wizard, options, state);  }}
查看完整描述

1 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

您實際上并沒有將要執行的 JS 傳遞到字符串模板中,您實際上是在執行該 JS 并將toString該執行的結果插入到模板中,您的變量賦值應該是:

      submitButtonTemplate = "<li><a href = \'#{0}\' onClick=" + "\"document.getElementById('studentForm').submit()\"" + " role=\"menuitem\">{1}</a></li>",


查看完整回答
反對 回復 2021-12-12
  • 1 回答
  • 0 關注
  • 289 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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