动态添加表格内容
function create_menu(infos){
var table = document.getElementById('menuTable');
for(var i = 0;i<infos.length;i++){
table.appendChild(mk_row(infos[i]));
}
}
function mk_cell(htmIfno){
var cell = document.createElement('td');
cell.innerHTML = htmIfno;
cell.setAttribute("class","td_menu");
return cell;
}
function mk_row(info){
var row = document.createElement('tr');
row.setAttribute("class","tr_menu");
var htmIfno = "";
htmlInfo = "<input class = 'button' type='button' value=" + info +" onClick='change_filed(event)'/>"
row.appendChild(mk_cell(htmlInfo));
return row;
}
获取事件产生对象
<input type="button" value="今年" onClick="fn(event)"/>
- 在回调函数中利用event.srcElement获取事件产生对象。通过js添的控件,利用this获取的对象是document,无法获取产生事件的对象。(待验证)
function change_filed(event){
var clickField = event.srcElement.value
alert(clickField)
}