联系表格7和默认无线电值

时间:2012-11-29 23:56:59

标签: jquery wordpress contact-form-7

我正在使用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>

2 个答案:

答案 0 :(得分:1)

您只需要为所选值“option2”

添加默认值:2
final MenuItem searchItem = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setMaxWidth(xxx);

答案 1 :(得分:0)

Contact Form 7生成的HTML不使用radio或option标签。它正在input type="radio"内使用span。因此,您的选择器与任何元素都不匹配。它应该是

'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');
});
相关问题