Ale*_*lex 21 javascript input onclick
我正在其中一个事件中创建用户输入:
var throwConnectBox = function() {
chat_box = document.getElementById('box');
div = window.parent.document.createElement('div');
input = window.parent.document.createElement('input');
input.type = "submit";
input.value = "Join chat";
input.onclick = "conn.send('$connect\r\n');";
div.appendChild(input);
chat_box.appendChild(div);
}
Run Code Online (Sandbox Code Playgroud)
...但结果输入没有onclick属性.我试着用
input.onclick = conn.send('$connect\r\n');
Run Code Online (Sandbox Code Playgroud)
......相反,但也没有工作.我究竟做错了什么?
Ste*_*son 39
试试这个:
input.onclick = function() { conn.send('$connect\r\n'); };
Run Code Online (Sandbox Code Playgroud)
史蒂夫
这里有一条线存在问题; 我已经为你纠正了它:
var throwConnectBox = function() {
chat_box = document.getElementById('box');
div = window.parent.document.createElement('div');
input = window.parent.document.createElement('input');
input.type = "submit";
input.value = "Join chat";
/* this line is incorrect, surely you don't want to create a string? */
// input.onclick = "conn.send('$connect\r\n');";?
input.onclick = function() {
conn.send('$connect\r\n');
};
div.appendChild(input);
chat_box.appendChild(div);
}
Run Code Online (Sandbox Code Playgroud)
那更有意义吗?
归档时间: |
|
查看次数: |
90078 次 |
最近记录: |