未在选择框中选择默认值

时间:2016-11-02 06:47:14

标签: html css select

我正在尝试从PHP文件中生成一个选择框:

JsonElement jelement = new JsonParser().parse(inputLine);
JsonArray jarray = jelement.getAsJsonArray();

JsonObject  jobject = jarray.get(i).getAsJsonObject();
//coyping this JsonObject to other reference so that it can be used for line items
JsonObject jobject123 = jobject;

JsonArray jarraylist = jobject123.getAsJsonArray("line_items");
String name[] = new String[jarraylist.size()];
String quantity[] = new String[jarraylist.size()];
String weight[] = new String[jarraylist.size()];

int j;
for( j=0;j<jarraylist.size();j++) {
    JsonObject jobjectlist = jarraylist.get(j).getAsJsonObject();
    name[j] = jobjectlist.get("name").getAsString();
    quantity[j] = jobjectlist.get("quantity").getAsString();

    JsonArray jarraymeta = jobjectlist.getAsJsonArray("meta");
    JsonObject  jobjectlist2 = jarraymeta.get(0).getAsJsonObject();
    weight[j] = jobjectlist2.get("value").getAsString();
}

默认情况下应选择值为<select class="form-control no-range-feature-val video-codec-list hidden"> <option value="none" selected="selected">Select</option> </select> 的选项,但不是。相反,我得到一个选择框,我必须手动选择none选项。

enter image description here

它可能是什么原因?我已经检查过Chrome,Firefox,Edge。他们都报告了相同的行为。

CSS:

Select

3 个答案:

答案 0 :(得分:1)

这适用于jfiddle https://jsfiddle.net/g6e6bjf7/,请显示您的css,因为这可能会导致问题

<select class="form-control no-range-feature-val video-codec-list hidden">
    <option value="none" selected="selected">Select</option>
</select>

答案 1 :(得分:0)

尝试这个..

<select class="form-control no-range-feature-val video-codec-list hidden">
            <option value="none" selected>Select</option>
            <option value="1">Select1</option>
     </select>

答案 2 :(得分:-1)

<select class="form-control no-range-feature-val video-codec-list">
    <option value="" selected="selected">Select</option>
</select>