Textarea通过jQuery创建 - 但不可编辑,为什么? [英] Textarea created through jQuery - but not editable, why?

查看:188
本文介绍了Textarea通过jQuery创建 - 但不可编辑,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的HTML代码...

I have this simple HTML code...

<div onclick='jsComment();'>Click to comment</div>

而且 jsComment()具有textarea和按钮的表单,并替换div的HTML内容

And the jsComment() function just creates a form with a textarea and a button and replaces HTML content of the div

function jsComment(id){

var form = '<form action="modules.php?name=some_url&id='+id+'" method="post" name="post">';
form += '<b>Post something!</b><br />';
form += '<textarea name="noticia" cols="100" rows="5" maxlength="299" style="overflow: hidden; border: none; border-top: 1px solid LightGrey; margin: 6px;"></textarea><br />';
form += '<input type="hidden" name="noticiaId" value="'+id+'" /><input type="submit" name="op" value="Comment!"></form>';   
jQuery('#noticia_'+id).html(form);

}

HTML生成正确,但我不能在textarea 。当我把光标放在textarea里它只是消失了...相同的提交按钮,它似乎被禁用...这里发生了什么问题?可能是一个CSS问题?

HTML is generated correctly, but I cannot write in the textarea. When I place the cursor inside the textarea it just disappears... same for the submit button, it appears to be disabled... what's going wrong here? Maybe a CSS question?

非常感谢

推荐答案

strong>更新

Update

请使用.replaceWith()代替,请参阅jsfiddle进行比较。

Use .replaceWith() instead, see jsfiddle for comparison.

尝试了多种方法来解决这个问题,我能想出的最好的方法是定期写(不动态)并显示它onclick。

I tried multiple ways to fix this the best way I could come up with is to write the regularly (not dynamically) and show it onclick.

查看小提琴: http://jsfiddle.net/c4urself/tFxDs/ 我尝试的所有选项

See the fiddle: http://jsfiddle.net/c4urself/tFxDs/ for all the options I tried

$("commentcontainer").click(function() {
    $(this).html("").next(".textareacontainer").show();
});

这篇关于Textarea通过jQuery创建 - 但不可编辑,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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