开发者

scope of the parameter in dynamic function call

In my javascript file im making dynamic call to a common function(more than one time) with different parameter value.

following is the code. edit question is the function and question id is the value return from database it will be different for each question. but once i created this im not getting the correct parameter value. edit question function contain the latest questionId f开发者_StackOverflow社区or all the call.

questionHTML = <div class="surveyQuestionBlock questionBorder" ><div  class="questionOpts"><ul >'
 +'<li><a onclick="editQuestion(questionId)">'
 +'Edit Question </a></li>'
 questionHTML.show();

thanks in advance


Try:

questionHTML = 
    '<div class="surveyQuestionBlock questionBorder">' +
      '<div class="questionOpts">' + 
        '<ul>' +
          '<li>' +
            '<a onclick="editQuestion(\'' + questionId + '\')">' +
              'Edit Question' + 
            '</a>' +
          '</li>' +
        '</ul>' +
      '</div>' +
    '</div>';

In other words, evaluating the current value of questionId and place it directly in the function call.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜