简体   繁体   English

在jQuery中document.ready函数外部的事件上调用函数

[英]Call functions on events outside document.ready function in jquery

I have this doubt. 我对此表示怀疑。 I remember earlier I used to define functions for events outside document.ready function in jquery. 我记得我以前曾为jquery中document.ready函数之外的事件定义函数。 Like 喜欢

$(function(){
// some function calls
});


$("#some-id").click(function(){
// instructions
})

And this used to work, but today I tried the same. 这曾经奏效,但今天我尝试了相同的方法。 I wanted to trigger a click on a button when some other button was clicked. 我想在单击某个其他按钮时触发一个按钮的单击。 It didn't seem to work. 它似乎没有用。 Although, I tried to alert outside document.ready and it worked just fine. 虽然,我试图提醒外部document.ready ,但效果很好。

I understand the use of document.ready but my click function should have worked right? 我了解document.ready的用法,但单击功能应该可以正常使用吗?

Oh, sorry! 哦对不起! I feel stupid! 我觉得我好笨! I was making changes to an existing code, written by someone else. 我正在更改别人编写的现有代码。 He has js included in the head. 他的头中包含js。 It is obvious for that to not work as the element is not included when my function is read! 很明显,由于读取我的函数时不包含该元素,因此不起作用!

Thanks guys! 多谢你们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM