如何让Contact Form 7中“Please select…”下拉选项不可选中?
问题:如何让Contact Form 7下拉菜单的“Please select…”选项不可选中?
我在使用Contact Form 7 Conditional Fields时,想让下拉菜单里的“Please select…”默认选项无法被选中。原本以为first_as_label属性能实现这个效果,但实际测试后发现该选项仍然可以被选中。
我的表单代码片段(简化后,未包含条件逻辑):
<label> How far along is the borrower in acquiring the property? The borrower…<span>*</span> </label> [select* property-ownership-how-far-along-is-the-borrower-in- acquiring-the-property-the-borrower first_as_label "Please select…" "is still looking for a property to acquire." "has identified the property." "has made an offer to purchase the property." "has the property under contract to purchase." "already owns the property."]
解决方法
我找到了有效的解决办法,只需两步操作:
- 修改表单短代码,将
first_as_label替换为class:wpcf7-select - 在页面代码的任意位置插入以下JavaScript脚本(注意将脚本中的
'Please select…'替换为你实际使用的默认选项文本):
(function ($) { 'use strict'; $(document).ready(function () { var $select = $('.wpcf7-select'); $select.each(function(e){ var first_option = $(this).find('option').first(); if(first_option.attr('value') == 'Please select…'){ first_option.attr('disabled', true); } }) }); })(jQuery)
内容的提问来源于stack exchange,提问作者Albert Pace
相关产品推荐
相关产品推荐

