我正在使用此方法将默认值传递给 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" />
<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>