繁体   English   中英

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

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

我想获取动态创建的 div 的 innerhtml 并将其放入剪贴板,但我不断收到类型错误。 我想访问 .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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM