<select id="Nazione" name="Nazione">
<option prefix='+93' value='AF' >Afghanistan </option>
<option prefix='+355' value='AL' >Albania </option>
<option prefix='+213' value='DZ' >Algeria </option>
<option prefix='+376' value='AD' >Andorra .... etc
</select>
Run Code Online (Sandbox Code Playgroud)
而这个js
$(document).ready(function() {
$('#Nazione').change(function(){
alert( $(this).find("option:selected").attr('prefix') );
alert( $(this).attr('prefix') );
});
});
Run Code Online (Sandbox Code Playgroud)
我有警报NULL ......为什么?
我在每个上使用以下函数<option>来确定它是否被选中:
var _matches = function(el, selector) {
var fn = el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector;
return fn.call(el, selector);
};
Run Code Online (Sandbox Code Playgroud)
它jsdom在NodeJS中运行良好,它适用于:checked 浏览器中的选择器(在复选框输入上),但不适用于:selected奇数的选择器.
我收到错误(在Chrome中):
未捕获的SyntaxError:无法在'Element'上执行'matches':':selected'不是有效的选择器.