假设我将一个blur函数附加到HTML输入框,如下所示:
<input id="myInput" onblur="function() { ... }"></input>
Run Code Online (Sandbox Code Playgroud)
有没有办法blur在函数内部获取导致事件触发的元素的ID (被点击的元素)?怎么样?
例如,假设我有这样的跨度:
<span id="mySpan">Hello World</span>
Run Code Online (Sandbox Code Playgroud)
如果我在输入元素具有焦点后立即单击跨度,则输入元素将失去焦点.该功能如何知道它mySpan被点击了?
PS:如果跨度的onclick事件发生在输入元素的onblur事件之前,我的问题就会解决,因为我可以设置一些状态值,表明已经点击了一个特定的元素.
PPS:这个问题的背景是我想在外部触发一个AJAX自动完成控件(来自可点击元素)来显示其建议,而不会因为blur输入元素上的事件而立即消失.所以我想检查blur函数是否单击了一个特定元素,如果是,则忽略blur事件.
我使用focusable属性强制SVG元素在HTML文档中获得焦点.
我需要通过TAB键在SVG标签中导航SVG元素.如文件中所述(http://www.w3.org/TR/SVGTiny12/interact.html#focusable-attr)
但我不能这样做.我已将focusable属性设置为true,并将tabindex每个元素设置为0.
这是我的代码:
<div style="border: solid yellow 2px;" tabindex="0">
<svg tabindex="0" width="900px" height="500px" viewBox="0 0 95 50" style="border: solid red 1px;" focusable="true"
xmlns="http://www.w3.org/2000/svg">
<g data-Name="group" tabindex="0" stroke="green" fill="white" stroke-width="5" data-tabindex="0" style="border: solid green 1px;" focusable="true">
<circle tabindex="0" cx="20" cy="25" r="5" focusable="true" data-Name="shape 1" data-tabindex="0" />
<circle tabindex="0" cx="40" cy="25" r="5" focusable="true" data-Name="shape 2" data-tabindex="0" />
<circle tabindex="0" cx="60" cy="25" r="5" focusable="true" data-Name="shape 3" data-tabindex="0" />
<circle tabindex="0" cx="80" cy="25" …Run Code Online (Sandbox Code Playgroud)