对于使用jQuery插件select2的国家/地区,我有一个选择框替换。
的jQuery
(function($) {
$(function() {
var isoCountries = [
{ id: 'QA', text: 'Qatar',},
{ id: 'CA', text: 'Canada'},
{ id: 'CN', text: 'China'},
{ id: 'DE', text: 'Germany'},
{ id: 'RU', text: 'Russia'},
{ id: 'IT', text: 'Italy'}
];
$("[data-type='country']").select2({
placeholder: "Select a country",
data: isoCountries
});
});
})(jQuery);
HTML
<form method="post">
<label for="country–32" id="label_country–32" class="control-label">Country *</label>
<select class="form-control select2 select2-hidden-accessible" id="country–32" name="country–32" data-type="country" tabindex="-1" aria-hidden="true">
<input type="submit" name="validatesubmit" value="Please validate" class="btn btnPrimary span-2 push-8">
</form>
--- 生成的select-formfield:
<select class="form-control select2 select2-hidden-accessible" id="country–32" name="country–32" data-type="country" tabindex="-1" aria-hidden="true">
country
<option value="QA">Qatar</option>
<option value="CA">Canada</option>
<option value="CN">China</option>
<option value="DE">Germany</option>
<option value="RU">Russia</option>
<option value="IT">Italy</option>
…
</select>
我现在的问题是,如果我发送表单,它会将id(CountryISO Shortname)保存为$_POST
中的值而不是text(Countryname)。我怎么能改变这个?
祝你好运, 扬
编辑: 在这里,您可以下载具有相同ID和文本的country-list: https://gist.github.com/janstieler/c715254d7d2994b80a74a37bb29e4439