jquery - 联系表 7 和默认单选值

标签 jquery wordpress contact-form-7

我正在使用this method将默认值传递到联系表单 7 选择字段。它工作正常,但我真的需要它与 radio 领域一起工作。

我尝试将 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>

最佳答案

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

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

关于jquery - 联系表 7 和默认单选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13636966/

相关文章:

php - 如何检测调用是否通过 jQuery 进行

javascript - 确保 jQuery on click 在 href 触发之前运行

html - 侧边栏链接不可点击

wordpress - 如何在 woocommerce 中的自定义产品模板上获取自定义产品属性

javascript - 如果输入是焦点且在跨度内,则添加类

jquery - Rails 从 javascript 删除链接调用

javascript - 如何覆盖谷歌地图上的相对定位

php - 从 wp_options 表获取选项值

javascript - 联系表格 7 - 重定向到另一个页面

jquery - 通过 AJAX (smoothstate.js) 加载页面时,联系表单 7 抛出 'wpcf7.initForm is not a function' 错误