只有 buttonEndNumber 事件监听器被正确触发。buttonStartNumber
没有做任何事情。
function appendNumberButtons()
{
var xpathExpression = 'id("delform")/div/div/div/div/div/div'
var xpathResult = document.evaluate(xpathExpression, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var buttonStartNumber
var buttonEndNumber
for ( var i=0 ; i < xpathResult.snapshotLength; i++ )
{
buttonStartNumber = document.createElement("input")
buttonStartNumber.setAttribute('type', 'button')
buttonStartNumber.setAttribute('value',"S"+i)
//buttonStartNumber.addEventListener('click', function(i){ return function(I){alert(i)} }(i), false);
listnerHelper(buttonStartNumber, i);
buttonEndNumber = document.createElement("input")
buttonEndNumber.setAttribute('type', 'button')
buttonEndNumber.setAttribute('value',"E"+i)
//buttonEndNumber.addEventListener('click', function(i){ return function(I){alert(i)} }(i), false);
listnerHelper(buttonEndNumber, i);
xpathResult.snapshotItem(i).innerHTML += " -> "
xpathResult.snapshotItem(i).appendChild(buttonStartNumber)
xpathResult.snapshotItem(i).innerHTML += " - "
xpathResult.snapshotItem(i).appendChild(buttonEndNumber)
}
}
我尝试过的事情:
一个额外的函数listenerHelper(object, i) -> nop buttonStartNumber
,buttonEndNumber
作为有和没有的数组listenerHelper(object, i) -> nop
我的错误在哪里?