【问题标题】:Contact Form 7 and default radio value联系表格 7 和默认单选值
【发布时间】:2012-11-29 23:56:58
【问题描述】:

我正在使用 this method 将默认值传递给 Contact Form 7 选择字段。它工作正常,但我真的需要它与无线电场一起工作。

我已尝试将 jquery 更改为:

jQuery(document).ready(function(){
        // get contents of hidden input; store in variable
        var val = jQuery("span.hiddendefault input").val();
        // set the "selected" attribute for option with value equal to variable
        jQuery('radio#style-one option[value=' + val + ']').attr('checked', 'checked');
});

和联系表 7:

[radio radio-525 id:style-one class:test-class "one" "two" "three" "four"] 

但未按要求检查单选按钮。请问大家有什么想法吗?

[编辑] 表单生成的 html:

<span class="wpcf7-form-control-wrap radio-525">
  <span id="style-one" class="wpcf7-form-control  wpcf7-radio test-class">
    <span class="wpcf7-list-item">
      <input type="radio" name="radio-525" value="one" />
      <span class="wpcf7-list-item-label">one</span>
    </span>
    <span class="wpcf7-list-item">
      <input type="radio" name="radio-525" value="two" />
      <span class="wpcf7-list-item-label">two</span>
    </span>
    <span class="wpcf7-list-item">
      <input type="radio" name="radio-525" value="three" />
      <span class="wpcf7-list-item-label">three</span>
    </span>
    <span class="wpcf7-list-item">
      <input type="radio" name="radio-525" value="four" />&nbsp;
      <span class="wpcf7-list-item-label">four</span>
    </span>
  </span>
</span>
<span class="wpcf7-form-control-wrap hiddendefault">
  <input type="hidden" name="hiddendefault" value="three" />
</span>

【问题讨论】:

  • 您是否从 url 获取默认值?还是它总是相同的默认值?可以包含表单的 html 吗?
  • 我通过一个按钮从 url 传递默认值:&lt;INPUT TYPE="button" value="i want this design!" onClick="parent.location='order-form?design-no=three'"&gt;。请查看表单生成的 html 的已编辑问题。

标签: jquery wordpress contact-form-7


【解决方案1】:

您只需为所选值“option2”添加默认值:2

[radio subcription default:2 "option1" "option2" "option3"]

【讨论】:

  • 我试图弄清楚如何为数字字段执行此操作,这导致我找到了解决方案:[number* cash default: "0"]
【解决方案2】:

Contact Form 7 生成的 HTML 不使用单选或选项标签。它在span 内使用input type="radio"。结果,您的选择器不匹配任何元素。应该是

'span#style-one input[value=' + val + ']'

在上下文中

jQuery(document).ready(function(){
    // get contents of hidden input; store in variable
    var val = jQuery("span.hiddendefault input").val();
    // set the "selected" attribute for option with value equal to variable
    jQuery('span#style-one input[value=' + val + ']').attr('checked', 'checked');
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-20
    • 2015-01-10
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多