我的webapp中有datagrid,我必须初始化那里的所有按钮。
我试过这个。
function initButtons() {
var i = 0;
var playBtn, markBtn;
for (;; i++) {
playBtn = document.getElementById('musicCloudForm:musicDataGrid:' + i
+ ':playMusicButton');
if (playBtn == null)
break;
playMusicButton[i] = playBtn;
playMusicButton[i].addEventListener('click', function() {
playPauseGridAudio(i);
}, false);
markBtn = document.getElementById('musicCloudForm:musicDataGrid:' + i
+ ':markMusicButton');
markMusicButton[i] = markBtn;
}
alert('Number of buttons - ' + i);
}
playPauseGridAudio
:
function playPauseGridAudio(number) {
alert('Button number ' + number);
//another code
}
在这种情况下如果我按任意按钮(在这种情况下我有3个按钮)我收到下一条消息:
Button number 3
我认为问题在于:
playMusicButton[i].addEventListener('click', function() {
playPauseGridAudio(i);}, false);