[英]Jquery click function not responding
Alright so for some reason whenever I try to click this input nothing happens, altho it should alert hello world...好吧,出于某种原因,每当我尝试单击此输入时,什么也没有发生,但它应该提醒您好世界...
<label>Ime Profesora</label><br/>
<input type='text' id='profesor_Ime' placeholder='Ime profesora...' /><br/>
<input type='submit' id='profesor_Submit' value='Dodaj Profesora'/>
And the JS和 JS
$("#profesor_Submit").click(function() {
alert("Hello world");
});
Here is the Jsfiddle https://jsfiddle.net/8y0hq6md/1/这是 Jsfiddle https://jsfiddle.net/8y0hq6md/1/
EDIT: I am loading the form dynamically from the SQL, could that maybe be the cause of the problem?编辑:我正在从 SQL 动态加载表单,这可能是问题的原因吗?
Make sure that the jQuery Library is included.确保包含 jQuery 库。
If that's already the case, also make sure that the document is "ready" by using $(document).ready()
.如果已经是这种情况,还可以使用
$(document).ready()
确保文档“准备好”。
Here's an example:下面是一个例子:
$(document).ready(function() {
// Your code here
});
..or the shorthand version: ..或简写版本:
$(function() {
// Your code here
});
You have not included jQuery library in your code.您尚未在代码中包含 jQuery 库。
$(document).ready(function() { $("#profesor_Submit").click(function() { alert("Hello world"); }); });
<label>Ime Profesora</label> <br/> <input type='text' id='profesor_Ime' placeholder='Ime profesora...' /> <br/> <input type='submit' id='profesor_Submit' value='Dodaj Profesora' /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
Updated jsFiddle: https://jsfiddle.net/8y0hq6md/10/更新 jsFiddle: https ://jsfiddle.net/8y0hq6md/10/
Okay so this was the solution好的,这就是解决方案
$(document.body).on('click', '#profesor_Submit' ,function(){
alert("Hello world");
});
This seems to work with it since I am loading the form dynamically这似乎适用于它,因为我正在动态加载表单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.