[英]Uncaught ReferenceError on click JQuery
I can not get the values from my button 我无法从按钮获取值
this Uncaught ReferenceError: reply_click is not defined at HTMLInputElement.onclick 此未捕获的ReferenceError:reply_click未在HTMLInputElement.onclick上定义
Note: I want my button to continue working! 注意:我希望我的按钮继续工作!
can anyone help me ? 谁能帮我 ?
function reply_click(clicked_id){
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
console.log('attached');
$('#openButton').on('click', function(data) {
console.log('clicked');
$.ajax({
type: "POST",
url: "/dash",
data: { _token: $('meta[name="csrf-token"]').attr(('src','{{url('/')}}'+data)}
})
.done(function(data){
console.log(data);
$('.inputbutton input').css("background-image", "url("+data+")");
})
.fail(function(data){
console.log('Error:', data);
});
});
});
} }
my button from blade.php 我的blade.php按钮
<div class="inputbutton">
<span class="text">TEXT</span>
<input type="submit" class="btTxt submit" value="" id="TEXT" onclick="reply_click(this.id)">
</div>
I don't think it is a good practice to use onclick, besides you should put your function inside the $(function() {})
instead 我认为使用onclick不是一个好习惯,除了应该将函数放在$(function() {})
So something like this: 所以像这样:
$(function() {
function reply_click(clicked_id){
// DO SOMETHING HERE
....
}
});
Also consider changing onclick to using $('#TEXT').click(function() {....})
还可以考虑将onclick更改为使用$('#TEXT').click(function() {....})
So overall, remove onlclick, and all of the codes should look like this: 因此,总体而言,删除onlclick,所有代码应如下所示:
$(function() {
function reply_click(clicked_id){
// DO SOMETHING HERE
....
}
$('#TEXT').click(function() {
// ON CLICK ACTIONS GO HERE
var input_id = $(this).attr('id'); // for example getting the id of the input
....
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.