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

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

單擊功能僅適用于第二次單擊

單擊功能僅適用于第二次單擊

PHP
米脂 2022-06-17 16:53:49
Wordpress/Woocommerce在構建中有以下代碼。問題是該按鈕僅在第二次單擊時有效。需要這個在第一次點擊時工作,我的代碼有什么問題?// Add button to hide Personalisationadd_action('woocommerce_single_product_summary', 'custom_text', 29);function custom_text() {    print '<button class="personlisation-button" onclick="myFunction()">Add Personalisation</button>';  }  // Script to toggle visibility<script type="text/javascript">  function myFunction() {    var x = document.getElementById("wcj_product_addons");    if (x.style.display === "none") {      x.style.display = "block";    } else {      x.style.display = "none";    }  }</script>
查看完整描述

1 回答

?
料青山看我應如是

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

最好添加一個檢查null。您可能在頁面上沒有這樣的元素。


function myFunction() {

  var x = document.getElementById("demo");

  if (x != null && x.style.display === "none") {

    x.style.display = "block";

  } else {

    x.style.display = "none";

  }

}

<button

  onclick="myFunction()"

>

  Toggle</button

>


<div id="demo">Hello world</div>


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 111 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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