gpt4 book ai didi

php - 如何在 Laravel 5 中返回带有 anchor 的 View ?

转载 作者:行者123 更新时间:2023-12-04 12:49:50 27 4
gpt4 key购买 nike

在我的 Controller 中

return view('pages.index', compact('errors'));

它工作正常,但我不知道如何将 View 返回到 anchor 。

return view('pages.index#contact', compact('errors'));

无效。出现这样的错误。

InvalidArgumentException in FileViewFinder.php line 137:
View [pages.index#contact] not found.

最佳答案

你可以使用一些 JS。首先传递 anchor 变量:

$anchor = 'contact';
return view('pages.index', compact('errors', 'anchor'));

然后使用hidden 或其他方式将数据传递给JS:

@if (isset($anchor))
<input type="hidden" name="anchor" value="{{ $anchor }}">
@endif

最后用JS移动页面:

$(function () {
if ( $( "[name='anchor']" ).length ) {
window.location = '#' + $( "[name='anchor']" ).val();
}
};

这只是一个给你一个想法的例子。

关于php - 如何在 Laravel 5 中返回带有 anchor 的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40673397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com