我正在使用js来更改div的内容,该内容输入我想用它们与Ajax, 我已经使用Firefox便笺簿调试此功能:在js中创建属性触发异常'不是函数'
function show(id){
var div = document.getElementById('com');
div.innerHTML = '';
var input1 = document.createElement('input')
.createAttribute('type').setAttribute('type', 'hidden')
.createAttribute('value').setAttribute('value',id)
.setAttribute('name','id');
var input2 = document.createElement('input')
.createAttribute('type').setAttribute('type', 'input')
.createAttribute('name').setAttribute('name', 'com');
var btn = document.createElement('button')
.createAttribute('onClick').setAttribute('onClick', 'post()');
btn.innerHTML = 'Comment';
div.appendChild(input1).appendChild(input2).appendChild(btn);
}
和我得到的是这样的:
/*
Exception: document.createElement(...).createAttribute is not a function
@Scratchpad/2:2
*/
我明白了什么,什么想法?