gpt4 book ai didi

javascript - 如何设置选择下拉列表国家和州的 'selected option'

转载 作者:行者123 更新时间:2023-11-29 23:51:22 24 4
gpt4 key购买 nike

我的过滤器搜索流动:

case 'region_state':
$output .= '
<div class="clear"></div>
<label><st>' . __( "Country", AT_TEXTDOMAIN ) . ':</s2></label>
<div class="select_box_1">
<select name="region_id" id="region_id" class="custom-select select_1">';
$output .= '<option value="0">' . __( "All", AT_TEXTDOMAIN ) . '</option>';
foreach ($view->add_widget( 'reference_widget', array( 'method' => 'get_regions' ), true ) as $key => $value) {
$output .= '<option value="' . $value['id'] . '">' . $value['name'] . '</option>';
}
// foreach (AT_VC_Helper::get_manufacturers() as $value => $key) {
// $output .= '<option value="' . $key. '">' . $value . '</option>';
// }
$output .= '
</select>
</div>
<label><s3>' . __( "State", AT_TEXTDOMAIN ) . ':</s3></label>
<div class="select_box_1">
<select name="state_id" id="state_id" class="custom-select select_1">
<option>All</option>
</select>
</div>';
$output .= '<input type="submit" value="' . __( "Search", AT_TEXTDOMAIN ) . '" class="btn_search btn-1 float-right" id="search_car_shortcode1"/>';
break;

数据来自reference_widget WordPress 管理员,我想要 1 个国家/地区为前美国州:纽约,默认情况下。

最佳答案

如果您所在的值是应该的值,您将需要在每个循环上进行测试“已选择”。

// the value you want to be selected
$region_id = $_REQUEST['region_id'];
// loop through the options
foreach ( $view->add_widget( 'reference_widget', array( 'method' => 'get_regions' ), true ) as $key => $value ){
// if the value matches, we want to output "selected"
$selected = ( $region_id == $value )? ' selected' : '';
$output .= '<option value="' . $value['id'] . '"' . $selected . '>' . $value['name'] . '</option>';
}

关于javascript - 如何设置选择下拉列表国家和州的 'selected option',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25635053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com