[英]How to use code from external .js files in blade.php?
I have resources/js/jquery.js files where I listen to button be pressed threw jQuery, and do some actions.我有资源/js/jquery.js 文件,我在其中听按钮被按下抛出 jQuery,并执行一些操作。 The problem is that I can't import jquery.js into my .blade.php.问题是我无法将 jquery.js 导入到我的 .blade.php 中。
I added jquery.min.js into by public/js.我通过 public/js 添加了 jquery.min.js。
What I have in .blade.php我在.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>
What I have in jquery.js我在jquery.js 中有什么
window.onload = function(){
$(document).ready(function(){
$('#registerButton').click(function(){
alert("Hello");
});
});
}
I need to get alert("Hello");
我需要得到alert("Hello");
The problem is that when click to the button nothing happens, I'm not sure if it bcs I added jquery.min.js wrongly, or just including my jquery.js script is wrong.问题是,当单击按钮时没有任何反应,我不确定是因为我错误地添加了 jquery.min.js,还是仅包含我的 jquery.js 脚本是错误的。 Or this is impossible and I have to add this in the bottom of the body in my .blade.php或者这是不可能的,我必须在我的 .blade.php 的正文底部添加它
<script type="text/javascript">
window.onload = function(){
$(document).ready(function(){
$('#registerButton').click(function(){
alert("Hello");
});
});
}
</script>
we assuming you have your js folders inside public/assets我们假设您在 public/assets 中有您的 js 文件夹
Then然后
Add external js something like this.添加外部js这样的东西。
<script src="{{ asset('js/jquery.min.js') }}"></script>
<script src="{{ asset('js/jquery.js') }}></script>
And Add space after/before 2 Curly brackets.并在 2 个花括号之后/之前添加空格。
I hope your problem will be resolve我希望你的问题会得到解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.