开发者

bind causing errors

开发者 https://www.devze.com 2023-03-01 00:23 出处:网络
I\'m noticing some errors that are occurring because of JQuery bind. What ha开发者_如何学Cppens is that when I submit a form, bind causes a javascript error to occur when the page that uses it is not

I'm noticing some errors that are occurring because of JQuery bind. What ha开发者_如何学Cppens is that when I submit a form, bind causes a javascript error to occur when the page that uses it is not loaded. When I comment the bind section out, the error goes away.

Here are the relevant lines of code.

  $('input').bind('click', function() {
    editor.post();
  });

  $("#submit").click(function () {
  ...

Is there a way to move the bind click function inside of the submit click function? If not, how can I stop this error from occurring?


This is the error:

editor is not defined
script.js
editor.post();


" bind causes a javascript error to occur when the page that uses it is not loaded."

If this is the case then move your code inside document.ready(), then no code will execute untill the document is loaded.

however if u need immediate click handler action with all input element then either use more specific selector to bind so that u can check existence of the code before runnning or use try-catch :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消