javascript onclick, onload, onmouseenter -- the basics
javascript onclick, onload, onmouseenter -- the basics
一直困扰我的一件事是,有时当我试图通过内联属性(onclick="bam();"
)分配jQuery函数时,它真正启动的可能性可能只有50%。
我知道这个函数很好,因为如果我分配一个常规的jQuery .on('click', function(){...})
,它就可以完美地工作。在阅读了一遍又一遍我在网上能找到的关于这件事的一切之后,我还是一如既往地无知。
我没有看到我需要看到的模式,这让我意识到我需要找到一个简单的教程。我不想学习JavaScript,我只想了解这一关键领域。
也许事件处理程序中存在错误,导致它无法"工作"——您可能认为它只在50%的时间内被调用,但实际上它在100%的时间内都被调用,并在50%的时候给出意外结果。
要查看是否有错误,您可以在Chrome或Firefox中使用firebug按F12并检查控制台。要查看函数是否被调用,函数中的第一行可能是:console.log("I am called");
,无论之后发生什么,您至少应该在控制台中看到该消息。
为了更好的设计,您永远不应该在html(内联)中声明应该触发什么事件,它应该在脚本中完成,这里是jQuery可以让您的生活更轻松的地方,因为它的方法在所有浏览器上都可以工作和行为相同。
相关文章:
- Intercept the cellSubmit jqGrid
- CSS中的游标属性似乎不适用于USB On The Go
- Appending the innerhtml of <th>
- jquery in the middle of html
- Can't get the tail to wag (animate) in three.js?
- jquery.proxy in the bootstrap-typeahead.js context
- What is the difference between `HTMLImports.whenReady` and `
- confuse about the parentNode
- momentjs toISOString without the "z"
- toDataURL(), from the Web onto my Computer
- JavaScript Get the child id
- jquery insert-before to text in the same DOM
- JQuery DataPicker add on the
- jQuery: setInterval effects on the server?
- gulp-concat twice the content
- What type is the 'return' keyword?
- Change the title on click of <li>
- DataTables-FixedHeader-多个tr in the ad对齐问题
- What is the reason for cloning the listeners array in nodejs
- javascript onclick, onload, onmouseenter -- the basics