且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JavaScript / JQuery中将HTML元素转换为字符串

更新时间:2022-10-15 09:41:34

You can do this:

var $html = $('<iframe width="854" height="480" src="http://www.***.com/embed/gYKqrjq5IjU?feature=oembed" frameborder="0" allowfullscreen></iframe>');    
var str = $html.prop('outerHTML');
console.log(str);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

FIDDLE DEMO

相关阅读

技术问答最新文章