duangou1868 2014-10-01 03:06
浏览 45

.Ajax,.text输入显示功能

var log = document.getElementById("log");


$(function(){
    $('textarea').keypress(function(e) {
        if (e.keyCode == 13 && !e.shiftKey) {

            log.innerHTML += "Company<br>";

            e.preventDefault();
            var frm = this.form; // don't submit the form yet

            log.innerHTML += "<br>";

            $.ajax({
                url: $(frm).attr('action'), // remember to specify which attribute you want
                data: $(frm).serialize(),
                dataType: "json",
                success: function() { 

                    log.innerHTML += "Ajax complete (form should be submitted now)<br>";

                    // submit the form when the ajax request is complete
                    // frm.submit();
                }
            });
        }
    });

});

<form action="#">
    <textarea name="comment"></textarea>
</form>

<div id="log"></div>

I am trying to set up the script to where I can display the results within the input. Is there a way to display the results whatever the user puts in the textarea below?

log.innerHTML += "Company<br>";

.innerHTML seems to be acting like a basic paragraph of text. All I need is to be able to display a list of links that are going to be put in the input to save them. Is there a way I can use .text() for the textarea?

Any help is appreciated, thank you!

  • 写回答

3条回答 默认 最新

  • dpmpa26468 2014-10-01 03:18
    关注

    use $("#log").text("").append($("textarea").val());

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法