Skip to content

Instantly share code, notes, and snippets.

@kindy
Created February 26, 2009 02:47
Show Gist options
  • Save kindy/70606 to your computer and use it in GitHub Desktop.
Save kindy/70606 to your computer and use it in GitHub Desktop.
//调用idIncrement(“quizForm.quiz.questions[0].options[0].textContent” , "questions")的时候返回
// quizForm.quiz.questions[1].options[0].textContent
//调用idIncrement(“quizForm.quiz.questions[0].options[0].textContent” , "options")的时候返回
// quizForm.quiz.questions[0].options[1].textContent
function idIncrement(s,p){
return s.replace(new RegExp('(' + p + '\\[)(\\d+)\\]'), function($a,$1,$2){
return $1 + ((parseInt($2, 10) || 0) + 1) + ']';
});
}
idIncrement('quizForm.quiz.questions[0].options[0].textContent','questions');
idIncrement('quizForm.quiz.questions[0].options[0].textContent','options');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment