Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery&;将HTML模板添加到Textarea;PHP_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 使用jQuery&;将HTML模板添加到Textarea;PHP

Javascript 使用jQuery&;将HTML模板添加到Textarea;PHP,javascript,php,jquery,html,Javascript,Php,Jquery,Html,所以我试图创建一个模板,它允许人们点击一个按钮,立即创建一个模板到一个文本区域,清除其中的所有数据 PHP: 来自“查看源”的jQuery: $(文档).ready(函数(){ $('#test1')。单击(函数(){ $('#ckeditor').html('test1'); }); $('#test2')。单击(函数(){ $('#ckeditor').html('test2'); }); }); HTML: 模板 如果您使用的是CKEDITOR, 例如,我认为将html字符串传递给ck

所以我试图创建一个模板,它允许人们点击一个按钮,立即创建一个模板到一个文本区域,清除其中的所有数据

PHP:

来自“查看源”的jQuery:


$(文档).ready(函数(){
$('#test1')。单击(函数(){
$('#ckeditor').html('test1');
});
$('#test2')。单击(函数(){
$('#ckeditor').html('test2');
});
});
HTML:

模板

如果您使用的是CKEDITOR, 例如,我认为将html字符串传递给ckeditor的正确方法是使用setData方法

CKEDITOR.instances.myinstance.setData('html here'); 

阅读更多内容

您是否在使用ckeditor插件?是的,我在模板中提供了它。我不确定您的ckeditor实例init在哪里,但如果您正在使用它,我认为将html字符串传递给ckeditor的正确方法是使用setData方法,例如
ckeditor.instances.myinstance.setData('html here')阅读更多您是一个传奇@3d7,您为我节省了数小时的搜索时间,但却毫无结果。非常感谢。我将把它作为一个答案,请投票并选择正确的我很高兴我帮助了
<script type="text/javascript" src="../../../../../../assets/js/jquery-1.10.2.min.js"></script>                             <!-- Load jQuery -->
<script>
        $(document).ready(function(){
           $('#test1').click(function(){
               $('#ckeditor').html('Test 1');
            });
$('#test2').click(function(){
               $('#ckeditor').html('Test 2');
            });
});</script>
<label class="col-sm-2 control-label">Templates</label>
<div class=\col-sm-8"><input type="button" class="btn btn-default btn-xs" id="test1" value="Test 1" />
<input type="button" class="btn btn-default btn-xs" id="test2" value="Test 2" />
</div>
</div>
<div class="col-12"><textarea name="ckeditor" id="" cols="100" rows="20" class="ckeditor"></textarea>
CKEDITOR.instances.myinstance.setData('html here');