Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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
Php 使用ajax向Textarea显示值不起作用_Php_Jquery_Ajax - Fatal编程技术网

Php 使用ajax向Textarea显示值不起作用

Php 使用ajax向Textarea显示值不起作用,php,jquery,ajax,Php,Jquery,Ajax,我想在textarea中显示所选下拉输入字段中的值。代码在正常输入字段中运行良好,但我需要将该字段作为textarea,如果将该字段更改为textarea,代码将停止工作 <textarea id="mytext" class="form-control" style="height: 300px" name="text"></textarea> $(document).ready(

我想在textarea中显示所选下拉输入字段中的值。代码在正常输入字段中运行良好,但我需要将该字段作为textarea,如果将该字段更改为textarea,代码将停止工作

<textarea id="mytext" class="form-control" style="height: 300px" name="text"></textarea>
    
$(document).ready(function(){

    $('.productid').select2();
    $(".productid").on('change', function(e){
        var productid = this.value;
        var tr=$(this).parent().parent();
        $.ajax({
            url:"getsignature.php",
            method:"get",
            data:{id:productid},
            success:function(data){
                tr.find ($('#mytext').val(data["signature"]));
            }
        })
    })
})

$(文档).ready(函数(){
$('.productid')。选择2();
$(“.productid”)。关于('change',函数(e){
var productid=this.value;
var tr=$(this.parent().parent();
$.ajax({
url:“getsignature.php”,
方法:“获取”,
数据:{id:productid},
成功:功能(数据){
tr.find($('#mytext').val(数据[“签名]);
}
})
})
})
这里#mytext是我的文本区域的id。 我有一个带有tinymce的文本区域

<script>

tinymce.init({ 选择器:“#mytext” });


$(文档).ready(函数(){
$('.productid')。选择2();
$(“.productid”)。关于('change',函数(e){
var productid=this.value;
var tr=$(this.parent().parent();
$.ajax({
url:“getsignature.php”,
方法:“获取”,
数据:{id:productid},
成功:功能(数据){
tr.find($('#mytext').html(数据[“签名]);
}
})
})
})
正如您所说,您的脚本在输入字段上运行良好,那么现在它在textarea上也应该运行良好

要获取textarea的值,需要使用html()而不是val()。

快乐编码:)


$(文档).ready(函数(){
$('.productid')。选择2();
$(“.productid”)。关于('change',函数(e){
var productid=this.value;
var tr=$(this.parent().parent();
$.ajax({
url:“getsignature.php”,
方法:“获取”,
数据:{id:productid},
成功:功能(数据){
tr.find($('#mytext').html(数据[“签名]);
}
})
})
})
正如您所说,您的脚本在输入字段上运行良好,那么现在它在textarea上也应该运行良好

要获取textarea的值,需要使用html()而不是val()。


快乐编码:)

使用
$('#mytext').val(…)
作为
tr.find
的参数的目的是什么?使用
$('#mytext').val(…)
作为
tr.find
的参数的目的是什么?测试代码
$(文档)。就绪(函数(){(“#显示”)。单击(函数(){($(“#测试”).html(“你好”)}); 谢谢,我忘了提一件事,比如,带编辑器的文本区。。我的文本区域是tinymce.init tinymce.init({selector:'#mytext'})$(function(){$(“#lang”).change(function(){var s=$(this.val();alert(s);tinyMCE.activeEditor.setContent(s);});已测试代码
$(文档).ready(函数(){$(“#显示”)。单击(函数(){$(“#测试”).html(“hello”);})谢谢,我忘了提一件事,比如,带编辑器的文本区。。我的文本区域是tinymce.init tinymce.init({selector:'#mytext'})$(function(){$(“#lang”).change(function(){var s=$(this.val();alert(s);tinyMCE.activeEditor.setContent(s);});
<textarea id="mytext" class="form-control" style="height: 300px" name="text"></textarea>
    
$(document).ready(function(){

    $('.productid').select2();
    $(".productid").on('change', function(e){
        var productid = this.value;
        var tr=$(this).parent().parent();
        $.ajax({
            url:"getsignature.php",
            method:"get",
            data:{id:productid},
            success:function(data){
                tr.find ($('#mytext').html(data["signature"]));
            }
        })
    })
})