从属性中选择适当的值
selecting proper value from attribute
我有一个选择框用于选择国家代码:-
<div class="selectWrap">
<select name="countryCode" id="countryCode"></select>
</div>
它使用javascript填充,并获得如下选项:-
<option data-phone-code="+91">91 (India)</option>
现在我只想选择+91的值。
I was trying this
var country = document.getElementById("countryCode");
var prefix = country.options[country.selectedIndex].value;
但是这会返回带有Country的Full值。
使用getAttribute,例如:
country.options[country.selectedIndex].getAttribute('data-phone-code');
相关文章:
- 在第二次选择中选择2更改属性
- 如何基于两个下拉选择从数据库中检索数据
- 自定义jquery选择器属性未在模拟器中激发
- Javascript:如何通过Regexp从属性中提取字符串
- jQuery 选择当属性 NAME 开头时
- 从属性生成字符串的 Angularjs
- 选择数据属性日期值早于当前服务器日期的元素
- 如何从对象中选择某些属性
- 从SequelizeJS中的表中选择特定属性
- 使用jquery从xml中选择一个属性
- 从属性选择器中提取值
- 如何设置为元素选择的属性并从其余部分移除属性
- 如何使用jquery从链接中选择href属性
- 从对象中选择给定属性的值到数组中
- 从集合中选择某些属性
- 从给定行中选择所有属性值(jQuery)
- 使用RegEx从字符串中获取标签,而不是在JavaScript中选择任何属性
- 仅对选中复选框的行从行选择数据属性
- 如何从 2 个表中选择一个属性
- 从属性中选择适当的值