使用OnClick在文本框中显示消息
我想在一个文本框上添加onClick(),该文本框是使用以下Java脚本方法在表中动态生成的.我只想调用一个Java脚本方法,它将通过此代码生成.
假设我想要在任何人点击用此代码生成的文本框时显示一条消息"hi".
选择 | 换行 | 行号
- function addRow()
- {
- var tbody = document.getElementById("table2").getElementsByTagName("tbody")[0];
- var row = document.createElement("TR");
- var cell1 = document.createElement("TD");
- var inp1 = document.createElement("INPUT");
- inp1.setAttribute("type","text");
- inp1.setAttribute("name","game_"+count);
- inp1.setAttribute("id","game_"+count);
- inp1.setAttribute("maxlength",11);
- inp1.setAttribute("size",10);
- inp1.setAttribute("value",document.forms.form1.elements.game.value);
- cell1.appendChild(inp1);
- var cell2 = document.createElement("TD");
- var inp2 = document.createElement("INPUT");
- inp2.setAttribute("type","text");
- inp2.setAttribute("name","number_"+count);
- inp2.setAttribute("id","number_"+count);
- inp2.setAttribute("maxlength",11);
- inp2.setAttribute("size",10);
- cell2.appendChild(inp2);
- row.appendChild(cell1);
- row.appendChild(cell2);
- }