简体   繁体   English

复制动态生成的 div 的内部 html

[英]copy the inner html of a dynamically generated div

I want to take the innerhtml of a dynamically created div and put it in the clipboard but I keep getting a Type error.我想获取动态创建的 div 的 innerhtml 并将其放入剪贴板,但我不断收到类型错误。 i want to access the .shortened div but I cant do it and I need help我想访问 .shortened div 但我不能这样做,我需要帮助

const results = document.createElement('div')
// call api
function result(url){
    fetch(https://api.shrtco.de/v2/shorten?url=${url})
    .then(res => res.json())
    .then(data =>{
        if (data.ok){
        var data= data
        results.innerHTML = <div class="result">
        <div class="sent">${data.result.original_link}</div>
        <div class="shortened" id="short"><div>${data.result.short_link}</div>
        <div class="copy-wrapper"></div><a href="#" class="copy" onClick= "copyLink()">Copy</a></div>
        </div>
        // create div 
        answer.appendChild(results)
    }else {
        alert('incorrect url')

    }
    mainBtn.innerHTML = "Shorten it!"
 
    })
    
   
 }

为什么需要访问innerHTML,什么时候可以把缩短的url直接放到copyLink函数参数中呢?

<div class="copy-wrapper"></div><a href="#" class="copy" onClick= "copyLink('${data.result.short_link}')">Copy</a></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 隐藏的元素,如果DIV是空的用于动态地生成一个HTML - Hide an element if div is empty for an html generated dynamically 复制一个div的内部html并使用javascript将其粘贴到另一个div中 - copy inner html of a div and paste it in an other div with javascript Angular 5:来自组件的访问元素内部html,用于动态生成的元素 - Angular 5: Access element inner html from the component for dynamically generated elements 将动态生成的 div 内容的副本发布到新页面 - Post copy of dynamically generated div content to new page 无法将PHP文件加载到使用javascript动态创建的内部HTML Div中 - Unable to load PHP file into a inner HTML Div created dynamically with javascript 如何从Web复制动态生成的源HTML? - How can I copy dynamically generated source HTML from the web? 如何使用动态生成的html输入类型实时填充div - how to live populate div using dynamically generated html input types 如何删除动态生成的DIV的lastchild元素并将html作为字符串返回 - how to remove the lastchild element of dynamically generated DIV and return the html as string 动态生成的内容DIV - Dynamically Generated Contents DIV 为什么内部html的src属性不能识别我动态生成的变量? - Why doesn't the src attribute of inner html recognize my dynamically-generated variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM