Append text to textarea with javascript

后端 未结 3 1235
离开以前
离开以前 2020-12-05 06:32

How can I append a list of text into a textarea?



  1. Hell
相关标签:
3条回答
  • 2020-12-05 07:13

    Tray to add text with html value to textarea but it wil not works

    value :

    $(document).on('click', '.edit_targets_btn', function() {
                $('#add_edit_targets').modal('show');
                $('#add_edit_targets_form')[0].reset();
                $('#targets_modal_title').text('Doel bijwerken');
                $('#action').val('targets_update');
                $('#targets_submit_btn').val('Opslaan');
    
                $('#callcenter_targets_id').val($(this).attr("callcenter_targets_id"));
                $('#targets_title').val($(this).attr("title"));
                $("#targets_content").append($(this).attr("content"));
    
                tinymce.init({
                    selector: '#targets_content',
                    setup: function (editor) {
                        editor.on('change', function () {
                            tinymce.triggerSave();
                        });
                    },
                    browser_spellcheck : true,
                    plugins: ['advlist autolink lists image charmap print preview anchor', 'searchreplace visualblocks code fullscreen', 'insertdatetime media table paste code help wordcount', 'autoresize'],
                    toolbar: 'undo redo | formatselect | ' + ' bold italic backcolor | alignleft aligncenter ' + ' alignright alignjustify | bullist numlist outdent indent |' + ' removeformat | image | help',
                    relative_urls : false,
                    remove_script_host : false,
                    image_list: [<?php $stmt = $db->query('SELECT * FROM images WHERE users_id = ' . $get_user_users_id); foreach ($stmt as $row) { ?>{title: '<?=$row['name']?>', value: '<?=$imgurl?>/image_uploads/<?=$row['src']?>'},<?php } ?>],
                    min_height: 250,
                    branding: false
                });
            });
    
    0 讨论(0)
  • 2020-12-05 07:23

    Give this a try:

    <!DOCTYPE html>
    <html>
    <head>
        <title>List Test</title>
        <style>
            li:hover {
                cursor: hand; cursor: pointer;
            }
        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $("li").click(function(){
                    $('#alltext').append($(this).text());
                });
            });
        </script>
    </head>
    <body>
    
        <h2>List items</h2>
        <ol>
            <li>Hello</li>
            <li>World</li>
            <li>Earthlings</li>
        </ol>
        <form>
            <textarea id="alltext"></textarea>
        </form>
    
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-05 07:25

    Use event delegation by assigning the onclick to the <ol>. Then pass the event object as the argument, and using that, grab the text from the clicked element.

    function addText(event) {
        var targ = event.target || event.srcElement;
        document.getElementById("alltext").value += targ.textContent || targ.innerText;
    }
    <textarea id="alltext"></textarea>
    
    <ol onclick="addText(event)">
      <li>Hello</li>
      <li>World</li>
      <li>Earthlings</li>
    </ol>

    Note that this method of passing the event object works in older IE as well as W3 compliant systems.

    0 讨论(0)
提交回复
热议问题