簡體   English   中英

如果顯示自定義字段,則顯示/隱藏按鈕

[英]Show/Hide a button if a custum field is display

我在我的網站(基於 wordpress)的結帳頁面中遇到問題。 我有兩種產品,對於每種產品,在結賬時,我創建了自定義字段來收集特定信息。 使用條件規則(通過插件),只有在選中特定選項列表時才會顯示某些字段。 當它們被隱藏時,分析代碼,我有這種情況:

<div class="form-row form-row-wide thwcfe-html-field-wrapper thwcfe-conditional-field" id="stud_no_req_field" data-name="stud_no_req" data-rules="[[[[{&quot;operand_type&quot;:&quot;field&quot;,&quot;value&quot;:&quot;2&quot;,&quot;operator&quot;:&quot;value_eq&quot;,&quot;operand&quot;:[&quot;student&quot;]}]]]]" data-rules-action="show" style="display: none;">...</div>

當它們出現時,“塊”中的樣式屬性會發生變化。

在頁面的末尾,我還有一個提交訂單的按鈕。

<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="Associati" data-value="Associati">Associati</button>

如果上面的自定義文件具有“display:block”,反之亦然(如果 div 具有“display:none”,則顯示按鈕),我正在尋找一個隱藏此按鈕的腳本。

我已經嘗試過這個腳本(在結帳頁面中),但沒有任何反應:

<script>
$(document).ready(function() {
if ($("#stud_no_req_field").style.display == "block")
{
    $("#place_order").style.display = "none";  
}
else
{
    $("#place_order").style.display = "block";
}
});
</script>

我還需要這個腳本是自動的(不需要點擊)並監聽 div 樣式的任何自動更改(在 html 標簽內)。

非常感謝!!! 你們是我的天使!

您使用了錯誤的代碼。 你應該做

$("#place_order")[0].style.display = 'none'; // I added [0]

或者使用 jQuery API ( https://api.jquery.com/css/ )

$("#place_order").css('display', 'none');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM