Ale*_*ove 4 jquery selecteditem drop-down-menu
我有一个单项HTML选择框,我想在将选择更改为新项目之前找出选择的项目.
到更改事件被触发时,已经太晚了:
$("select").change(function () {
var str = "";
$("select option:selected").each(function () {
// this will get me the current selected item (the new one)
str += $(this).text() + " "; });
})
Run Code Online (Sandbox Code Playgroud)
文档说'当控件失去输入焦点并且自获得焦点后其值已被修改时,更改事件将触发.
但是,捕获'blur'事件似乎也不是正确的事件,并且没有"onFocusLost"类型的事件.
这是否可以跨浏览器兼容的方式,没有很多箍跳?
这应该在更改之前捕获值.一旦用户打开选择菜单,但在实际选择某些内容之前,将抓取该值.
$(document).ready(function(){
$('select').focus(function(){
var theValue = $(this).attr('value');
});
});
Run Code Online (Sandbox Code Playgroud)