It looks like you're building DOM elements from strings.(看起来您是从字符串构建DOM元素。)
You just need to add some quotes around result.name:(您只需要在result.name周围添加一些引号即可:)
'<input type="button" onClick="gotoNode('' + result.name + '')" />'
You should really be doing this with proper DOM methods though.(您实际上应该使用适当的DOM方法来执行此操作。)
var inputElement = document.createElement('input');
inputElement.type = "button"
inputElement.addEventListener('click', function(){
gotoNode(result.name);
});
?document.body.appendChild(inputElement);?
Just be aware that if this is a loop or something, result
will change before the event fires and you'd need to create an additional scope bubble to shadow the changing variable.(请注意,如果这是一个循环之类的东西, result
将在事件触发前发生变化,您需要创建一个额外的作用域气泡以遮盖变化的变量。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…