【问题标题】:Condition to display text next to total amount in Gravity forms在重力形式的总量旁边显示文本的条件
【发布时间】:2017-12-14 12:05:28
【问题描述】:

我需要根据最终金额使用重力形式在总金额旁边显示一个文本。那么,如果金额超过 600,我如何在代码中显示例如“此文本”?

<script type="text/javascript">

gform.addFilter( 'gform_product_total', function(total, formId){

 if(total > 600)
 document.body.innerText = 'this text';

return total;

} );

</script>

上面的公式似乎工作除了文本的一部分,它会自动将我重定向到一个空白页面,文本显示在顶部。我需要文本显示在总 div 的旁边或下方。 有谁知道如何得到它?谢谢。

【问题讨论】:

  • 你也必须发布你的 HTML
  • html 来自总 div?
  • 1.332,45 €
  • ok 然后做 document.querySelector('.ginput_container ginput_container_total').innerText += 'this text';而不是 document.body.innerText = 'this text';
  • 我试过你提到的但没有显示任何文字

标签: javascript wordpress gravity-forms-plugin


【解决方案1】:

在重力表单管理页面中为该产品字段提供自定义 CSS 类。 https://docs.gravityforms.com/product/#appearance

如果您将类指定为“product-field”,则字段 html 将生成为

<div class="product-field ginput_container ginput_container_total"> 
<span class="ginput_total ginput_total_18">1.332,45 €</span> 
<input type="hidden" name="input_51" id="input_18_51" class="gform_hidden" value="1332.45"> 
</div>

那么你应该通过它的类来获取这个字段。将 html 附加到字段 div。

<script type="text/javascript">

gform.addFilter( 'gform_product_total', function(total, formId){
 if(total > 600) {
  $('.product-field').append('<div>this text</div>');
 }
 return total;
});

</script>

【讨论】:

  • 所以我在总字段中添加了一个类,但它仍然没有附加文本...我想显示总和旁边的文本
  • 请检查是否在字段html中添加了类。如果已添加,请在控制台中检查您正在获取 $('.product-field') 的 DOM 元素
  • 中添加:
  • 1.800,00 €
  • 我尝试使用所有可能的类,但似乎没有一个显示文本。没有其他方法可以显示文本,例如显示字段吗?因此,当条件是总金额超过 600 时,会显示文本,否则会隐藏文本或不显示文本。
  • 在上面的html中,你添加了哪个类?
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签