如果显示custum字段,则显示/隐藏按钮

时间:2020-03-20 22:27:06

标签: javascript html css wordpress woocommerce

我的网站(基于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标记内)。

非常感谢!!!你是我的天使!

1 个答案:

答案 0 :(得分:0)

您使用了错误的代码。你应该做

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

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

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