1
간단하게 보이지만 작동하지 않습니다.
동적으로 생성 된 <option>
에서 몇 가지 맞춤 데이터 속성을 얻으려고합니다.
옵션이 제대로 생성하고 해당 구문이 올바른지 :
<option value="xml/airports/africa.xml" data-pos="5" data-airport="Noumérat - Moufdi Zakaria Airport">Noumérat - Moufdi Zakaria Airport</option>
을 나는이 값을 기록 콘솔하려고하지만 때, 나는 undefined
가 계속.
은 겉으로는 간단하고 짧은에 대한 스크립트 :
$(document).ready(function() {
var sel = $('select'); //its the only select on the page
sel.change(function() {
//some variations I have tried:
var n = sel.attr('data-airport');
var f = sel.val()); //****this is pulling fine
var i = sel.attr('data-pos');
console.log(n, i);
console.log(sel.attr('data-pos');
console.log($(this).attr('data-pos');
console.log($('select').attr('data-pos');
})
})
나는 아무 소용 의무 구글 검색 ... 좋은 아이디어 누구 짓을했는지?
가 그 ... 덕분에 같은 간단한 것이었다 생각해야합니다! – mikedugan