zepto区别于jquery获取select表单选中的值

在jquery下,我们获取select表单选中的值通常是通过$('select').val()来实现,这样的方式简单又明了,或者通过$('select option[selected]').text()$('select option:selected').text()这样的代码来实现,其实本来$('select').val()这种方式就很好,但在项目中我想获取给每个option自定义的属性的值,我就要通过后者的类似的写法$('select option:selected').attr('data-id')来实现,但是这种方法在zepto下就会报出"Failed to execute 'querySelectorAll' on 'Document': 'select option:selected' is not a valid selector."的错误,这让我曾经一度认为是我的写法有错误,后来通过网上查资料,大神们才让我知道了这种写法不存在在zepto的API里,他们给出了这样的解决办法:

办法一:

$('select option').not(function(){ return !this.selected }).attr('data-id');

办法一适用于jquery和zepto。

办法二:

$('select  option').eq($('select').attr("selectedIndex")).attr('data-id');

办法二只适用于zepto,在jquery下会报出undefined,所以不适用于jquery。