jQuery - 如何检测在 select 中被 select 编辑的选项,当它不改变 selection
jQuery - how to detect an option being selected in a select, when it doesn't change the selection
我有一堆 select 列表 PDF 文件。当用户从 select 中选择一个 PDF 时,我会在屏幕上显示该 pdf。这是从 "change blur".
上的事件侦听器触发的
如果他们随后关闭了其中包含 pdf 的 div,并想再次打开它,他们必须从下拉列表中再次 select。
但是,我发现为了再次显示 pdf,他们需要 select 一个 不同的 pdf,然后打开 select再次选择他们想要的:换句话说,如果您打开 select,然后单击 "Done"(在移动设备上)或单击已经 select 的选项(桌面) , 然后因为它没有改变,所以不会触发显示 PDF。
我认为将 "blur" 添加到正在侦听的事件中就可以了 - select 关闭不会触发它的模糊事件吗?但这似乎没有帮助。
这是我的代码:
$("body").on("change blur", ".pdf-file-select", function(e){
//get the pdf uri from the selection and show the pdf
});
谢谢。
编辑 - 根据调查,blur
仅在我点击 select 外部时触发 - 当我关闭 select.
时它不会触发
改为使用 click
事件
$("body").on("click", ".pdf-file-select", function(e){
//get the pdf uri from the selection and show the pdf
});
我有一堆 select 列表 PDF 文件。当用户从 select 中选择一个 PDF 时,我会在屏幕上显示该 pdf。这是从 "change blur".
上的事件侦听器触发的如果他们随后关闭了其中包含 pdf 的 div,并想再次打开它,他们必须从下拉列表中再次 select。
但是,我发现为了再次显示 pdf,他们需要 select 一个 不同的 pdf,然后打开 select再次选择他们想要的:换句话说,如果您打开 select,然后单击 "Done"(在移动设备上)或单击已经 select 的选项(桌面) , 然后因为它没有改变,所以不会触发显示 PDF。
我认为将 "blur" 添加到正在侦听的事件中就可以了 - select 关闭不会触发它的模糊事件吗?但这似乎没有帮助。
这是我的代码:
$("body").on("change blur", ".pdf-file-select", function(e){
//get the pdf uri from the selection and show the pdf
});
谢谢。
编辑 - 根据调查,blur
仅在我点击 select 外部时触发 - 当我关闭 select.
改为使用 click
事件
$("body").on("click", ".pdf-file-select", function(e){
//get the pdf uri from the selection and show the pdf
});