有没有办法将点击事件绑定到jquery中的div的左边界? [英] Is there any way to bind a click event to a div's left border in jquery?
本文介绍了有没有办法将点击事件绑定到jquery中的div的左边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个div
< div id =preview>
< / div>
有没有办法将click事件绑定到这个div的左边框?
在此先感谢。
解决方案
div {
height:100px;
border:4px纯黑色;
padding:10px;
}
请尝试此方法
点击(功能(e){
if(e.offsetX< 5){
alert('点击左边框!');
}
});
修改 - 更好的版本
$('div')。click(function(e){
if(e。 offsetX <= parseInt($(this).css('borderLeftWidth'))){
alert('clicked on the left border!');
}
});
I have a div
<div id="preview">
</div>
Is there any way to bind a click event to this div's left border?
Thanks in advance.
解决方案
div {
height:100px;
border:4px solid black;
padding:10px;
}
Please try this method
$('div').click(function(e){
if( e.offsetX < 5){
alert('clicked on the left border!');
}
});
Edit - Better version
$('div').click(function(e){
if( e.offsetX <= parseInt($(this).css('borderLeftWidth'))){
alert('clicked on the left border!');
}
});
这篇关于有没有办法将点击事件绑定到jquery中的div的左边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文