您的位置:首页 > Web前端 > JavaScript

zeptojs中获取select选中的option的值

2015-10-09 11:18 477 查看

第一种方法

// get OPTION elements for which `selected` property is true
$('option').not(function(){ return !this.selected })


问题

:$(‘option[selected]’) only finds options that have their selected attr set in the html.It does not find values the the user has selected themselves.

结论:

This is expected behavior. Such CSS selectors match attribute values, which don’t change with user interaction. Theselected property of the element changes, but attribute doesn’t.

第二种方法

$("#ID").val()  获取选中的value
$("#ID option").eq($("#ID").attr("selectedIndex")).text()    获取选中的文本值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  zeptojs select option