Javascript jquery上的单击事件不起作用
我已经用php打印了一个输入元素的echo,我需要使用jquery获取click事件id。下面是我试图获取的代码 php(使用ajax将echo元素转换为index.php): 为什么它不起作用?请建议尝试以下方法:Javascript jquery上的单击事件不起作用,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我已经用php打印了一个输入元素的echo,我需要使用jquery获取click事件id。下面是我试图获取的代码 php(使用ajax将echo元素转换为index.php): 为什么它不起作用?请建议尝试以下方法: window.onload=function(){ $("#something").click(function(){ alert("hi"); }); } $( document ).ready(funct
window.onload=function(){
$("#something").click(function(){
alert("hi");
});
}
$( document ).ready(function() {
$("#something").click(function(){
alert("hi");
//doesnt work
});
});
如果这不起作用,那么您需要显示您的代码 将onclick()函数写入input
本身。它会起作用的
有关详细信息,请单击
.
.
函数showValue(){
警报(“hi”);
返回false;
}
以下是正在运行的代码:
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<input type='button' id='test' value='accept me'/>
<script>
$(document).ready(function(){
$('#test').bind('click', function(){
alert('Hello')
})
})
</script>
$(文档).ready(函数(){
$('#test').bind('click',function(){
警报(“你好”)
})
})
如果要单击按钮,请使用按钮类型而不是submit是否将其包装在$(文档)中。准备好了(function()函数?我会想象它在DOM中存在之前绑定到#某物。请尝试`$('input')。on('click','#某物',function(){//where});您确定要在输入html后编写click事件,并编写对jquery文件位置的javascript引用,是的,请将其包装在document.ready中,如@thepiyush所说,并阅读有关事件的内容delegation@Doron:请检查我的答案。忘记提到$(function(){$(“#某物”)。单击(function(){alert(“hi”);//doesnt work});如果它有助于window.onload=function(){$(“#something”)。单击(function(){alert(“hi”)}}似乎OP不知道堆栈上的情况如何。但似乎没有用。哦,你能做些什么。
$( document ).ready(function() {
$("#something").click(function(){
alert("hi");
//doesnt work
});
});
<form ... >
.
.
<input type='submit' id='something' onclick="return showValue();" value='accept me'/>
</form>
<script>
function showValue() {
alert('hi');
return false;
}
</script>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<input type='button' id='test' value='accept me'/>
<script>
$(document).ready(function(){
$('#test').bind('click', function(){
alert('Hello')
})
})
</script>