【发布时间】:2021-01-12 21:43:45
【问题描述】:
我知道我可以使用旧的 put 字段为 select 标签设置 selected 属性:
<select name="country" id="state" onChange="loadlist(this.value);" >
<option value="usa" {{ (old('state') == 'usa') ? 'selected' : '' }}>USA</option>
<option value="grm" {{ (old('state') == 'grm') ? 'selected' : '' }}>Germany</option>
<option value="eng" {{ (old('state') == 'eng') ? 'selected' : '' }}>England</option>
</select>
但在这种形式中,我有另一个选择标签,它从 Jquery 文件中用于加载选项:
<select name="state" id="state" class="form-control arrow-black">
<option value="">Select country</option>
</select>
Jquery 代码:
function loadlist(country){
with(document.getElementById('state'))
{
options.length = 0;
if(country == ''){
options[0] = new Option('Select country' , '');
}
if (country == 'usa') {
options[0] = new Option('Select' , '');
options[1] = new Option('NewYork' , 'NewYork');
options[2] = new Option('Florida' , 'Florida');
options[3] = new Option('California' , 'California');
}
if (country == 'grm') {
options[0] = new Option('Select' , '');
options[1] = new Option('Bayern' , 'Bayern');
options[2] = new Option('Hamburg' , 'Hamburg');
options[3] = new Option('Berlin' , 'Berlin');
}
if (country == 'eng') {
options[0] = new Option('Select' , '');
options[1] = new Option('Buckingham' , 'Buckingham');
options[2] = new Option('Cambridge' , 'Cambridge');
options[3] = new Option('London' , 'London');
}
}
}
如何为第二个选择标签设置{{ (old('state') == 'The state name') ? 'selected' : '' }}?
【问题讨论】:
标签: javascript jquery laravel laravel-5