外部化文本文件中typeInTextarea的内容

用户名

我目前正在尝试将文本文件中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
})
用户名

//用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总是在帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章