防止laravel link_to_action双击执行 [英] prevent laravel link_to_action to perform on double click
问题描述
在我的laravel项目负责人中,我编写了一个用于批准和拒绝约会的代码.拒绝约会后,该条目将从数据库中删除,并再次重定向到列表.
In my laravel project controller i wrote a code for approve and reject appointments. on rejecting the appointment the entry will be deleted from database and redirect again to the listing table.
我在拒绝部分使用了此代码
i used this code in reject section
html_entity_decode(link_to_action('AdminController@getAtoggle', '<img src="'.$icon2.'"alt=asknow width=20 height=20/>',array($data['appointment_id'],2),array('title'=>'Click Me For Reject','ondblclick' => "event.preventDefault();")));
但是当双击" Trying to get property of non-object "
时仍显示错误.我很清楚这是因为,第一次单击时,该条目已从数据库中删除,因此第二次单击时,没有要删除的条目在db中.但是如果用户双击我不想向他们显示此错误消息或404页面.
But still when double clicks " Trying to get property of non-object "
error is showing. I clearly know this occurs because , on first click the entry is deleted from database so the second click there is no entry to delete in db. but in case the user double clicks i don't want to show them this error message or 404 page.
有什么办法可以防止双击.我在"ondblclick"
中尝试了"alert"
,但这同时显示了警报和错误页面.
so is there any way to prevent double clicks. i tried "alert"
in "ondblclick"
but that shows both alert and error page.
推荐答案
我认为问题在于您正在尝试使用event
进行初始化.
I think the problem is you're trying to use event
before it's been initialised.
尝试将代码从<a>
标记移至JS文件,尝试使用此jQuery
Try move the code from the <a>
tag to your JS files, try this jQuery
$( "#target" ).dblclick(function(event) {
event.preventDefault();
});
我将event
传递到回调中,以便您可以运行preventDefault()
.
I'm passing in event
into the callback so you can run preventDefault()
.
这篇关于防止laravel link_to_action双击执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!