documet.getElementBy没有传递值

时间:2018-10-09 05:14:01

标签: javascript html

我的JavaScript代码是:

    document.getElementById('district').value =  dist.long_name "this line is passing the value"
    document.getElementById('city').value =  route.long_name "this doesn't"

View the image of page

我的HTML是:

<div class="form-group">
    <label>District</label>
    <select id="district" class="form-control">
        <option id="district" selected='selected' style="display:none;"><label id="district"></label> </option>
        <option>Thrissur</option>
        <option>Kozhikode </option>
        <option>Palakkad </option>
    </select>
</div>

<div class="form-group">
    <label>City</label>

    <select id="city" class="form-control"> 
        <option id="city" selected='selected' style="display:none;"><label id="city"></label> </option>   
        <option>opt1</option>
        <option>opt2 </option>
        <option>opt3 </option>
    </select>
</div>

我遇到了错误,该如何解决:

  

documet.getElementBy没有传递值

1 个答案:

答案 0 :(得分:0)

您应该在HTML中具有唯一的ID。

 <select id="city" class="form-control"> 

<label id="city"></label>

不可接受。