我正在尝试触发鼠标单击的事件,用户单击按钮并触发事件,一旦用户单击输入字段,请参阅下面的代码或jsFiddle下面: -
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); }); });我在jsfiddle上有一个例子
我遇到的问题是,一旦用户点击输入字段,该功能需要停止/完成。 但是,如果用户在单击第一个输入字段后单击它,则再次运行该功能。
我试过推杆
return false;代码内部阻止进一步传播,但这没有奏效。
任何帮助将不胜感激。
提前致谢。
I am currently trying to trigger an event on a mouse click where the user clicks a button and it triggers an event, once the user clicks on an input field, Please see code below or jsFiddle Below:-
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); }); });I have an example on jsfiddle
The issue that I am having is once the user clicks in the input field the function needs to stop/finish. But instead the if the user click the second input field after clicking the initial one it runs the function again.
I have attempted putting
return false;Inside the code to stop further propagation but this has not worked.
Any help would be greatly appreciated.
Thanks in advance.
最满意答案
在输入字段上单击一次后,可以使用.off()删除eventlistener。 像这样的东西:
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); $('input').off('click'); }); });you can use .off() to remove eventlistener after you click once on the input field. something like this:
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); $('input').off('click'); }); });停止第二次触发功能事件(Stopping function event firing a second time)我正在尝试触发鼠标单击的事件,用户单击按钮并触发事件,一旦用户单击输入字段,请参阅下面的代码或jsFiddle下面: -
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); }); });我在jsfiddle上有一个例子
我遇到的问题是,一旦用户点击输入字段,该功能需要停止/完成。 但是,如果用户在单击第一个输入字段后单击它,则再次运行该功能。
我试过推杆
return false;代码内部阻止进一步传播,但这没有奏效。
任何帮助将不胜感激。
提前致谢。
I am currently trying to trigger an event on a mouse click where the user clicks a button and it triggers an event, once the user clicks on an input field, Please see code below or jsFiddle Below:-
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); }); });I have an example on jsfiddle
The issue that I am having is once the user clicks in the input field the function needs to stop/finish. But instead the if the user click the second input field after clicking the initial one it runs the function again.
I have attempted putting
return false;Inside the code to stop further propagation but this has not worked.
Any help would be greatly appreciated.
Thanks in advance.
最满意答案
在输入字段上单击一次后,可以使用.off()删除eventlistener。 像这样的东西:
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); $('input').off('click'); }); });you can use .off() to remove eventlistener after you click once on the input field. something like this:
$('.button').click(function () { $('*').css( 'cursor', 'crosshair' ); $('input').one("click",function (event) { alert(event.pageX, event.pageY); $('input').off('click'); }); });
发布评论