gpt4 book ai didi

javascript - 我有 2 个文本区域。连续单击“添加描述”按钮时,两个文本区域的文本将合并到第一个文本区域中

转载 作者:行者123 更新时间:2023-11-28 18:03:37 25 4
gpt4 key购买 nike

我能够实现这一点,但我还需要每个新条目都有一个时间/日期戳。这是一个 fiddle 链接:

https://jsfiddle.net/Anupriya24/pstynje9/

脚本:

    var count=0;
$('.addDescBtn').on('click', function() {
count++;
if(count<=1){
if($("#description").val()==""){
alert("Please add to existing description field.");
$("#description").val("");
$("#description").removeAttr("readonly");
count=0;
}
else {
$("#descriptionHolder").append('<div class="form-group col-md-12 pad0 mar-t20" id="newDesc"><label class="col-md-3 pad0 visible-none" for="description1">Description:</label><textarea rows="5" cols="50" class="form-control col-md-9" id="description1" placeholder="Description"></textarea> </div>');
}
}
if($('#descriptionHolder').find('#newDesc').length){
var text=$("#description").val().trim();
var text1=$("#description1").val();
var combinedText=text+"\n"+text1+"\n";
$("#description").val(combinedText);
$("#description").attr('readonly', 'readonly');
$("#description1").val("");
}

});

HTML

                        <div class="form-group col-md-12 pad0" id="descriptionHolder">
<label class="col-md-3 pad0" for="description">Description:</label>
<textarea rows="5" cols="50" class="form-control col-md-9" id="description" placeholder="Description" ></textarea>
</div>
<div class="form-group col-md-12 pad0">
<input type="button" class="addDescBtn orangeBtn btn fright" value="Add Description" id="addDescription"/>
</div>

最佳答案

试试这个:

   var count=0;
$('.addDescBtn').on('click', function() {
count++;
if(count<=1){
if($("#description").val()==""){
alert("Please add to existing description field.");
$("#description").val("");
$("#description").removeAttr("readonly");
count=0;
}
else {
$("#descriptionHolder").append('<div class="form-group col-md-12 pad0 mar-t20" id="newDesc"><label class="col-md-3 pad0 visible-none" for="description1">Description:</label><textarea rows="5" cols="50" class="form-control col-md-9" id="description1" placeholder="Description"></textarea> </div>');
}
}
if($('#descriptionHolder').find('#newDesc').length){
var text=$("#description").val().trim();
//Just added new Date() with your string; It will give current timestamp.
var text1=$("#description1").val() + new Date();
var combinedText=text+"\n"+text1+"\n";
$("#description").val(combinedText);
$("#description").attr('readonly', 'readonly');
$("#description1").val("");
}

});

关于javascript - 我有 2 个文本区域。连续单击“添加描述”按钮时,两个文本区域的文本将合并到第一个文本区域中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com