在我的控制器中
return view('pages.index', compact('errors'));
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我不知道如何将视图返回到锚点。
return view('pages.index#contact', compact('errors'));
Run Code Online (Sandbox Code Playgroud)
不工作。出现这样的错误。
InvalidArgumentException in FileViewFinder.php line 137:
View [pages.index#contact] not found.
Run Code Online (Sandbox Code Playgroud)
你可以使用一些JS。anchor首先传递变量:
$anchor = 'contact';
return view('pages.index', compact('errors', 'anchor'));
Run Code Online (Sandbox Code Playgroud)
然后使用 hidden或其他东西将数据传递给JS:
@if (isset($anchor))
<input type="hidden" name="anchor" value="{{ $anchor }}">
@endif
Run Code Online (Sandbox Code Playgroud)
最后使用JS移动页面:
$(function () {
if ( $( "[name='anchor']" ).length ) {
window.location = '#' + $( "[name='anchor']" ).val();
}
};
Run Code Online (Sandbox Code Playgroud)
这只是一个给你一个想法的例子。
| 归档时间: |
|
| 查看次数: |
1910 次 |
| 最近记录: |