Laravel Form 在提交时运行 JS 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18179223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:15:39 来源:igfitidea点击:
Laravel Form run JS function onsubmit
提问by Adrian Bartholomew
I have a function that I want called on submission of my Laravel Form for Ajax purposes. How can I go about this where the page does not submit and reload?
我有一个函数,我想在为 Ajax 目的提交我的 Laravel 表单时调用它。我该如何解决页面不提交和重新加载的问题?
This works: (but the Enter btn does not execute)
这有效:(但 Enter btn 不执行)
<?php echo Form::open(); ?>
<?php echo Form::button('Search', array('id'=>'searchbtn', 'class'=>'button radius right', 'onclick'=>'myFunction(this.form)')); ?>
<?php echo Form::close(); ?>
This does not:
这不会:
<?php echo Form::open(array('onsubmit' => 'myFunction(this)')); ?>
<?php echo Form::submit('Search', null, array('id'=>'searchbtn', 'class'=>'button radius right')); ?>
<?php echo Form::close(); ?>
采纳答案by Adrian Bartholomew
<?php echo Form::open(array(null, null, 'onsubmit' => 'myFunction(this); return false;')); ?>
<?php echo Form::submit('Search', null, array('id'=>'searchbtn', 'class'=>'button radius right')); ?>
<?php echo Form::close(); ?>
Yayy. Now I could use my Enter button!
耶。现在我可以使用我的 Enter 按钮了!