感谢查利特菲在这个问题上的帮助。
我知道我的解释不够准确,不足以理解这个案子。我在复制代码时还引入了一个错误。
有一个真正的问题,我已经找到了一个达到目标的解决方案,但我不确定为什么它不起作用,为什么它现在起作用。
有两个发展步骤:
1-只需在单击标题中的一个跨距时执行stuff(但在按下shiftkey时不涉及聚焦元素的其他stuff)。
HTML结构包含:
<h5>
<span class="toc-target" tabindex="1000"> <!-- puts the "target" on top -->
<span class="H_title">
Adhérent
</span>
</span>
<span class="endof_tocid"></span>
</h5>
前两级跨度的原因是,它是由两个不同的软段完成的,需要两个不同的类。
相关代码(自三年前起)为:
$(".H_title")
.click(function(event) {
if ( ... ) { do stuff1 }
return true; // go on action
} )
.focusin(function() {...do_stuff2a);} );
.focusout(function() {...do_stuff2b);} );
//END
2-在某些情况下,我需要一个单选按钮,在这种情况下不执行stuff1(只需在标题中添加一个输入),然后HTML代码变成:
<h5>
<span class="toc-target" tabindex="1000"> <!-- puts the "target" on top -->
<span class="H_title">
<input name="user_type" type="radio" value="adh">
Adhérent
</span>
</span>
<span class="endof_tocid"></span>
</h5>
我写的js代码不起作用:
$(".H_title")
.click(function(event) {
if ( ... ) { do stuff1 }
return true; // go on action of the click on the button
} )
.focusin(function() {...do_stuff2a);} );
.focusout(function() {...do_stuff2b);} );
//END
在我看来,这个错误似乎是单选按钮在没有代码管理事件的情况下无法进入h_title范围。注意:这与聚焦动作和事件是一样的。
如果没有为click事件编写jquery代码,则一切正常运行。
//BEGIN
$(".toc-target > input")
.click( function(){ return true; });
.focusin(function() {return true; } );
.focusout(function() {return true; } );
$(".H_title")
.click(function(event) {
if ( ... ) { do stuff1: move-top }
return true; // go on actions
} )
.focusin(function() {...do_stuff2a);} );
.focusout(function() {...do_stuff2b);} );
//END
有了这段代码,点击输入函数,什么是行为:
1 -
$(".toc-target > input")
事件将被引发并返回true,这似乎不会导致单选按钮和事件气泡的正常选择。
2-H_标题得到他的点击事件,并正常执行。
现在focusin focusout还不能与按钮结合使用,我认为问题来自于与单击的冲突(单击时标题获得焦点的事实)。
我必须澄清一些关于人体工程学的要点和兼容性(可在个人电脑和手机上获得)。
另一个解决方案可能是从h_u title到“input”的“传播”
但是我还没有找到一个好的方法来把所有需要的事情都整合到stuffxx中,并清楚地将操作分离开来。
可能是我错了,也可能是你有一些建议要用最好的方式去做。
最好的问候
高音