为了账号安全,请及时绑定邮箱和手机立即绑定

如何在blade.php 中使用来自外部.js 文件的代码?

如何在blade.php 中使用来自外部.js 文件的代码?

PHP
森林海 2021-10-22 10:57:42
我有资源/js/jquery.js 文件,我在其中听按钮被按下抛出 jQuery,并执行一些操作。问题是我无法将 jquery.js 导入到我的 .blade.php 中。我通过 public/js 添加了 jquery.min.js。我在.blade.php 中有什么<form id="RegisterForm" method="GET">    <input type="text" name="username" id="username">    <input type="text" name="email" id="email">    <input type="text" name="password" id="password">    <input type="text" name="password2" id="password2">    <input type="submit" value="REGISTER" id="registerButton"></form><script src="{{asset('js/jquery.min.js')}}"></script><script src="/js/jquery.js"></script>我在jquery.js 中有什么window.onload = function(){$(document).ready(function(){    $('#registerButton').click(function(){        alert("Hello");    }); });}我需要得到 alert("Hello");问题是,当单击按钮时没有任何反应,我不确定是因为我错误地添加了 jquery.min.js,还是仅包含我的 jquery.js 脚本是错误的。或者这是不可能的,我必须在我的 .blade.php 的正文底部添加它<script type="text/javascript">    window.onload = function(){        $(document).ready(function(){            $('#registerButton').click(function(){                alert("Hello");            });        });    }</script>
查看完整描述

1 回答

?
慕慕森

TA贡献1856条经验 获得超17个赞

我们假设您在 public/assets 中有您的 js 文件夹,

然后

添加类似这样的外部 js。


<script src="{{ asset('js/jquery.min.js') }}"></script>

<script src="{{ asset('js/jquery.js') }}></script>

并在 2 个花括号之后/之前添加空格。


我希望你的问题会得到解决


查看完整回答
反对 回复 2021-10-22
  • 1 回答
  • 0 关注
  • 180 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号