Javascript jQuery在.html()加载的表单中查找textarea并在其上应用脚本

Javascript jQuery在.html()加载的表单中查找textarea并在其上应用脚本,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我正在为一个小论坛编写一个脚本,我想在其中加载一个表单,以便在单击“添加新主题”时填写。到目前为止一切都很好。。问题是。。我需要在加载的表单的文本区域中预先设置一些脚本,以添加一些HTML编辑器功能 我的剧本是: $(document).ready(function(){ $('div#new_topic_div').hide(); $('a.new_topic_li').on("click",function(e){ var parent

我正在为一个小论坛编写一个脚本,我想在其中加载一个表单,以便在单击“添加新主题”时填写。到目前为止一切都很好。。问题是。。我需要在加载的表单的文本区域中预先设置一些脚本,以添加一些HTML编辑器功能

我的剧本是:

    $(document).ready(function(){
        $('div#new_topic_div').hide();
        $('a.new_topic_li').on("click",function(e){
        var parentID = $(this).closest('ul').attr('id');
        var form = "<form id=add_new_topic_form action='' method=POST>\n <input type=hidden id=cat_id value='" + parentID + "' /><table class=add_new_topic_form_table border=0>\n <tr><td colspan=2><?=tjcg_add_topic;?></td></tr><tr><td valign=top><?=tjcg_form_post_title;?></td><td valign=top colspan=2 ><input type=text name=new_topic_title id=new_topic_title><td></tr>\n <tr><td valign=top><?=tjcg_form_post_subject;?></td><td colspan=2 valign=top><textarea name=new_topic_text id=new_topic_text class=test rows='5' cols='45'></textarea></td></tr><tr><td class=add_topic_result></td><td width=50px><input type=submit class=submit_btn value='<?=tjcg_form_submit;?>' /></td><td class=form_result></td></tr>\n <table>\n </form>";
        e.preventDefault();
        var parent= $(this).closest('li');
        var checked = $(this).attr('checked_link');
        if (checked == 0)
        {
        parent.find('div#new_topic_div').html(form).show(200);
        $(this).attr('checked_link',"1");
        }
        else{
        parent.find('div#new_topic_div').html('').hide(200);
        $(this).attr('checked_link',"0");
        }
        });
    });
将表单加载到divnew\u topic\u div后,我想将以下脚本应用到加载表单中的textarea字段

$textarea.htmlarea

可能吗?

在这一行之后:

parent.find('div#new_topic_div').html(form).show(200);
只要这样做:

parent.find('div#new_topic_div textarea').htmlarea();

您需要将html属性放在引号中,例如

var form = '<form id="add_new_topic_form" method="post" action="...">';
或者简单地说:

parent.find('div#new_topic_div').html(form).show(200, function() {
    // do stuff with $("#add_new_topic_form");
    $("textarea").htmlarea();
});
使用

例如:

parent.find('div#new_topic_div').html(form).show(200, function() {
    $.getScript("some_script_for_textareas.js", function() {
        // Got script, do stuff with textarea
    });
});
$("#container_id/and or class").on("focus", "#new_topic_div", function (e) {
     $(this).htmlarea();
});

有什么问题?你的意思是你尝试在textarea标签中添加一些脚本。。那么这里的问题在哪里呢?您可以尝试对您的textarea id执行加载或html或其他操作。。