HTML
//C# 6.0 way
var g1 = parent?.child?.child?.child;
if (g1 != null) // TODO
//C# 5.0 way
var g1 = parent.elvisExtension().child.elvisExtension().child.elvisExtension().child;
if (g1 != null) // TODO
JS
<input type="text" list="countries" name="mycountry" />
<datalist id="countries">
<option value="India">India</option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Germany">Germany</option>
<option value="France">France</option>
</datalist>
我希望当列表选项选择时,警报框会显示该值。
答案 0 :(得分:3)
您需要将侦听器绑定到输入元素
var a = document.getElementsByName('mycountry')[0];
a.addEventListener('change', function() {
alert(this.value);
});
&#13;
<input type="text" list="countries" name="mycountry" />
<datalist id="countries">
<option value="India">India</option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Germany">Germany</option>
<option value="France">France</option>
</datalist>
&#13;