在html select中将默认选项值保留为空 [英] Leave default option value empty in html select

查看:906
本文介绍了在html select中将默认选项值保留为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html select,它使用foreach循环从查询中填充了DATA。看起来像这样

I have an html select that is populated with DATA from a query using a foreach loop. It looks something like this

$client = $wpdb->get_results("SELECT string FROM `file` WHERE 
`code` = 002 AND `status` = 2");

echo 'Filter by client: ';
  echo '<select name="client_list">';
  foreach ($client as $key => $row) {
    $value = $row->string;
    echo 
  '<option value='.$value.'>'
  .$value. '</option>';
  }
  $client = $_GET['client_list'];
  echo '</select>';

它用作过滤器,用于根据所选的选项值显示数据。它过滤的表看起来像这样

It serves as a filter to display data based on the selected option value. The table that it filters looks somehting like this

   |client  | file              | 
   |------  |-------------------|
   |client1 | file00000         |
   |client2 | file00002         |

现在我想将html的第一个选项值(默认值)设为空。我该怎么做?

Now I want to make the first option value (the default value) of the html empty. How do I do this?

推荐答案

您可以使用此

      $client = $wpdb->get_results("SELECT string FROM `file` WHERE 
     `code` = 002 AND `status` = 2");

    echo 'Filter by client: ';
    echo '<select name="client_list"><option value=""></option>';
    foreach ($client as $key => $row) {
        $value = $row->string;
        echo 
       '<option value='.$value.'>'
        .$value. '</option>';
    }
    $client = $_GET['client_list'];
    echo '</select>';

这篇关于在html select中将默认选项值保留为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆