【问题标题】:externalize content of a typeInTextarea in a text file在文本文件中外部化 typeInTextarea 的内容
【发布时间】:2018-01-03 15:07:16
【问题描述】:

我目前正在尝试将文本文件中 typeInTextarea 的内容外部化。这个想法是当我点击一个按钮时,一个文本文件的所有内容都进入一个文本区域光标所在的地方(我不希望新内容删除旧内容)...... 我使用该代码:

function typeInTextarea(el, newText) {
  var start = el.prop("selectionStart")
  var end = el.prop("selectionEnd")
  var text = el.val()
  var before = text.substring(0, start)
  var after  = text.substring(end, text.length)
  el.val(before + newText + after)
  el[0].selectionStart = el[0].selectionEnd = start + newText.length
  el.focus()
  return false
}
$("button").on("click", function() {
  typeInTextarea($("textarea"), "  SOME TEXT  ")
  return false
})

我正在努力实现这样的目标:

$("button").on("click", function() {
  typeInTextarea($("textarea"), "  SOMETEXT.txt  ")
  return false
})

【问题讨论】:

    标签: javascript jquery cursor textarea external


    【解决方案1】:

    //已解决//用php

    我的 php

    <?php
    $file3 = file_get_contents('media/test3.txt');
    $file4 = file_get_contents('media/test4.txt');
    ...
    ...
    ?>
    

    我的html

    <a href="" data-text="<?php echo $file3 ?>">Test 1</a> test3<br/>
    <a href="" data-text="<?php echo $file4 ?>">Test 2</a> test4<br/>
    <textarea rows="5" cols="40" name="replycontent" id="replycontent"></textarea>
    

    我的 js

    <script type="text/javascript">
        $("a[data-text]").click(function(){
      var value = $("#replycontent").val();
       $("#replycontent").val(value+$(this).attr("data-text"));
       return false;
    })
    </script>
    

    php 总是有帮助的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多