在文本文件中外部化 typeInTextarea 的内容
externalize content of a typeInTextarea in a text file
我目前正在尝试将 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 总是在帮助
我目前正在尝试将 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 总是在帮助