gpt4 book ai didi

jquery - 如何用jquery获取textarea的内容

转载 作者:行者123 更新时间:2023-12-03 22:49:56 27 4
gpt4 key购买 nike

我是 jquery 新手。我对某些功能感到震惊,我有两个文本区域框,让我们假设

第一个文本区域ID是first_ta第二个文本区域 ID 是 secondary_ta

<textarea id="first_ta" rows="2" cols="2"></textarea>
<textarea id="second_ta" rows="2" cols="2"></textarea>

1.我想要first_ta的内容在“p”标签中,并且该标签应该由jquery本身生成。

2. 我希望 "div" 标签中的 secondary_ta 内容应由 jquery 生成,并且如果我重复,则 div 的 id 应动态更改流程。

请帮我找到上述问题的解决方案。

最佳答案

I want the content of first_ta in a "p" tag and the tag should be generated by jquery itself.

$('<p>').html($('#first_ta').val()).appendTo('body');

我想要“div”标签中的 secondary_ta 内容,该标签应由 jquery 和 div 的 id 生成

// assuming you've got a variable genId defined somewhere in your code with a start 
// value of 1
$('<div>').html($('#second_ta').val()).attr('id', 'generated-id-' + genId++).appendTo('body');

关于jquery - 如何用jquery获取textarea的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4933048/

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