添加onclick属性以使用JavaScript输入 [英] Add onclick property to input with JavaScript

查看:140
本文介绍了添加onclick属性以使用JavaScript输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在其中一个事件中创建用户输入:

I am creating a user input at one of the events:

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);
}

...但结果输入没有onclick属性。我试图使用

... but the resulting input does not have onclick property. I tried to use

    input.onclick = conn.send('$connect\r\n');

...相反,但也没有工作。我做错了什么?

... instead, but didn' work either. What am I doing wrong?

推荐答案

试试这个:

 input.onclick = function() { conn.send('$connect\r\n'); };

Steve

这篇关于添加onclick属性以使用JavaScript输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆