单击动态创建的TextArea上的侦听器

时间:2013-07-08 07:16:54

标签: javascript html5

我在javascript中有一个动态创建的textArea。我把它设为“readonly”并使用字符串设置值现在我希望每当点击这个textArea时,应该调用一个函数。但我正在尝试,但所有功能都不起作用。任何帮助将不胜感激:

这是我的代码:

    textarea = document.createElement("textarea");
                               textarea.setAttribute('readonly', 'readonly'); 
                               textarea.setAttribute("cols",35);
                               textarea.setAttribute("rows",5);
                               textarea.setAttribute("style","overflow:hidden;color: white; font-size: 30px;margin-left:10px;position:relative;margin-top:5px;background:transparent;border:thin;outline:none;");
                               textarea.value=all_sel_questions[(question_shuffled_array[i])];
textarea.addEventListener('onClick', clickonTextArea, false); //Here i am trying to enable click listner on this textarea.

启用onClick列表器的第二种方法:

textarea.onClick = clickonTextArea; //但这并不是要求点击是否要求加载html。

1 个答案:

答案 0 :(得分:0)

尝试更改onClick以单击eventlistener

textarea.addEventListener('click', clickonTextArea, false);