Php 使用按钮onclick重定向
我使用的是Laravel框架和刀片模板引擎 我想做的是,在我的视图中有两个按钮,当单击时,会将您重定向到另一个视图。我尝试的代码是:Php 使用按钮onclick重定向,php,laravel,Php,Laravel,我使用的是Laravel框架和刀片模板引擎 我想做的是,在我的视图中有两个按钮,当单击时,会将您重定向到另一个视图。我尝试的代码是: <button type="button" onclick="{{ Redirect::to('users.index') }}">Button</button> 按钮 您可以尝试此操作(假设刀片模板中有此代码): 这意味着,您有一个如下所示的路由声明: Route::get('users/index', array('uses' =&
<button type="button" onclick="{{ Redirect::to('users.index') }}">Button</button>
按钮
您可以尝试此操作(假设刀片模板中有此代码):
这意味着,您有一个如下所示的路由声明:
Route::get('users/index', array('uses' => 'UserController@index', 'as' => 'users.index'));
在这种情况下,也可以使用:
<button type="button" onclick="window.location='{{ route("users.index") }}'">Button</button>
按钮
输出将是相同的。是的,您基本上需要使用URL帮助程序来生成URL(与只放置类似的内容而不是PHP帮助程序相同):
按钮
虽然我不明白为什么不能使用“a href”标记而不是按钮,如下所示:
<a href="{{ URL::route('users.index'); }}">My button</a>
<button type="button" onclick="window.location='{{ route("users.index") }}'">Button</button>
<button type="button" onclick="window.location='{{ URL::route('users.index'); }}'">Button</button>
<a href="{{ URL::route('users.index'); }}">My button</a>