开发者

Javascript\JQuery function does not work without an alert

I have a problem with my 2 JQuery\Javascript functions. My problem is that when I dont have alerts in both my functions, both the functions don't work properly, and the event agument and eventtarget parameters are overwritten.

please advise on the solution for this.

 function SubmitAdded() {

      $(document).ready(function (){
      var arrAdded = new Array();
      $('#JQAddedList li').each(function (i) {
          arrAdded[i] = $(this).text();
      });

          __doPostBack("AddA开发者_StackOverflow社区ctivity", arrAdded);
         // alert('if this alert is commented out, function does not work.');

 });
  }


I usually take situations like this to mean that there is a timing issue involved. The alert box causes the script to pause long enough for the the state to change. If the alert doesnt occur then the script speeds through too quickly and your page/script wasnt in the state you thought it would be in when it runs through.

I'm not sure without more details, but offhand your script looks wrong in that it is wiring up a document ready event inside another function. You should try refactoring it into two functions and see if that fixes it.

$(document).ready(function (){
    var arrAdded = new Array();
    $('#JQAddedList li').each(function (i) {
        arrAdded[i] = $(this).text();
    });
});

function SubmitAdded() {
    __doPostBack("AddActivity", arrAdded);
}


// alert('Added ('if this alert is commented out, function does not work.');

You seem to have one parenthesis to many...

or as someone more intelligent than me said:

"It's not the parenthesis that there's one too many of, it's the excess quote. – Xhalent"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜