为了账号安全,请及时绑定邮箱和手机立即绑定

获得html元素的字符串形式

获得html元素的字符串形式

炎炎设计 2019-05-20 17:16:48
html:script:varmybox=document.getElementsByTagName("li");document.write(mybox[1].innerHTML);输出的结果:image/i2.png这个图片会显示在网页上,我可否得到这个字符串?
查看完整描述

2 回答

?
慕码人2483693

TA贡献1860条经验 获得超9个赞

varmybox=document.getElementsByTagName("li");alert(mybox[1].innerHTML);
                            
查看完整回答
反对 回复 2019-05-20
?
慕娘9325324

TA贡献1783条经验 获得超4个赞

javascript:
varmybox=document.getElementsByTagName("li");
document.write(''+mybox[0].innerHTML+'');
-----------20180528修改-----------
已被废弃,可使用<pre>和<code>元素来代替<xmp>元素<pre><pre>
                            </div>
                            <div class="js-show-reply-btn hide-answer-morebtn hide">查看完整回答</div>
                        </div>
                        <div class="ctrl-bar js-wenda-tool">
                            <span class="moco-ico-btn moco-btn-gray-l js-agree-with " data-ques-id="555365" data-answer-id="548018" data-hasop=""><i class="icon-thumb-revert"></i></span>
                            
                            <span class="moco-ico-btn moco-btn-gray-l js-oppose " data-ques-id="555365" data-answer-id="548018" data-hasop=""><i class="imv2-thumb_down"></i><em>反对</em></span>
                            <a href="javascript:;" class="reply-del js-replay-answer-list" data-answer-id="548018" data-ques-uid="6798334">回复</a>

                                                                                                                <span class="time r">2019-05-20</span>
                        </div>
                                                <div class="reply-con">
                            <ul class="reply-list">
                                                            </ul>
                                                        
                        </div>
                    </div>
                </div>
                            </div>
                                </div>
    </div>

    <div class="right-block">
        <div class="detail-info">
            <ul class="number">
                <li>
                    <em>2</em>
                    <span>回答</span>
                </li>
                <li>
                    <em>0</em>
                    <span>关注</span>
                </li>
                <li>
                    <em>838</em>
                    <span>浏览</span>
                </li>
            </ul>
                        <a href="javascript:void(0)" data-id="555365" title="关注" class="moco-btn moco-btn-gray-l js-collection-btn">
                <span class="js-detail-follow">关注</span>
            </a>
                        <div class="info-footer">
                <div class="small-share l wd-share">
                    <ul class="share-wrap">
                        <li class="weichat-posi js-top-share">
                            <div class="bdsharebuttonbox weichat-style bdshare-button-style0-16" data-tag="share_1" data-quesid="555365">
                                <a href="#" class="bds_weixin icon-nav icon-share-weichat" data-cmd="weixin" title="分享到微信"></a>
                                <a href="#" class="bds_qzone icon-nav icon-share-qq" data-cmd="qzone" title="分享到QQ空间"></a>
                                <a href="#" class="bds_tsina icon-nav icon-share-weibo" data-cmd="tsina" title="分享到新浪微博"></a>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="status-box r">
                                    </div>
            </div>
        </div>
        <!-- 详情页广告位 -->
        <div id="#wendaDetailRight"></div>
        
        <!-- <div class="adver-con">
                    </div> -->
        <!-- 相关问题 -->
                <div id="wendaDetailRight"></div>
        
                    <div class="recommend-zhuanlan">
                <div class="title">慕课专栏</div>
                <a class="more" href="/read" target="_blank">更多<i class="imv2-arrow2_r"></i></a>
                <ul>
                                            <li class="clearfix">
                            <a href="/read/74?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                <div class="img l" style="background-image:url(//img1.sycdn.imooc.com/5e906f08000176b005400720.jpg)">
                                                                    </div>
                            </a>
                            <div class="text_con r">
                                <a href="/read/74?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                    <p class="title">数据结构与算法(前端版)</p>
                                </a>
                                <div class="info">
                                    <span>共24小节</span>
                                    <i class="imv2-dot_samll"></i>
                                    <span>492人已购买</span>
                                </div>
                                <div class="price_con clearfix">
                                                                            <div class="price l ">
                                            <p class="ori l">¥ 58.00</p>
                                        </div>
                                                                        <div class="btns r">
                                                                                    <a href="javascript:;" onclick="$('#js-signin-btn').click();">
                                                <div class="goBuy">马上订阅</div>
                                            </a>
                                                                            </div>
                                </div>
                            </div>
                        </li>
                                            <li class="clearfix">
                            <a href="/read/72?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                <div class="img l" style="background-image:url(//img1.sycdn.imooc.com/5e6af0f50001b61d05400720.jpg)">
                                                                    </div>
                            </a>
                            <div class="text_con r">
                                <a href="/read/72?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                    <p class="title">Web前端开发修炼指南</p>
                                </a>
                                <div class="info">
                                    <span>共30小节</span>
                                    <i class="imv2-dot_samll"></i>
                                    <span>1765人已购买</span>
                                </div>
                                <div class="price_con clearfix">
                                                                            <div class="price l ">
                                            <p class="ori l">¥ 58.00</p>
                                        </div>
                                                                        <div class="btns r">
                                                                                    <a href="javascript:;" onclick="$('#js-signin-btn').click();">
                                                <div class="goBuy">马上订阅</div>
                                            </a>
                                                                            </div>
                                </div>
                            </div>
                        </li>
                                            <li class="clearfix">
                            <a href="/read/70?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                <div class="img l" style="background-image:url(//img1.sycdn.imooc.com/5e5c85e1000116c505400720.jpg)">
                                                                    </div>
                            </a>
                            <div class="text_con r">
                                <a href="/read/70?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                    <p class="title">解锁前端面试体系核心攻略  </p>
                                </a>
                                <div class="info">
                                    <span>共50小节</span>
                                    <i class="imv2-dot_samll"></i>
                                    <span>2380人已购买</span>
                                </div>
                                <div class="price_con clearfix">
                                                                            <div class="price l ">
                                            <p class="ori l">¥ 78.00</p>
                                        </div>
                                                                        <div class="btns r">
                                                                                    <a href="javascript:;" onclick="$('#js-signin-btn').click();">
                                                <div class="goBuy">马上订阅</div>
                                            </a>
                                                                            </div>
                                </div>
                            </div>
                        </li>
                                            <li class="clearfix">
                            <a href="/read/68?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                <div class="img l" style="background-image:url(//img1.sycdn.imooc.com/5e40b3010001fac905400720.jpg)">
                                                                    </div>
                            </a>
                            <div class="text_con r">
                                <a href="/read/68?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                    <p class="title">高薪之路&mdash;前端面试精选集</p>
                                </a>
                                <div class="info">
                                    <span>共25小节</span>
                                    <i class="imv2-dot_samll"></i>
                                    <span>1345人已购买</span>
                                </div>
                                <div class="price_con clearfix">
                                                                            <div class="price l ">
                                            <p class="ori l">¥ 58.00</p>
                                        </div>
                                                                        <div class="btns r">
                                                                                    <a href="javascript:;" onclick="$('#js-signin-btn').click();">
                                                <div class="goBuy">马上订阅</div>
                                            </a>
                                                                            </div>
                                </div>
                            </div>
                        </li>
                                            <li class="clearfix">
                            <a href="/read/38?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                <div class="img l" style="background-image:url(//img1.sycdn.imooc.com/5d15f85300011f5f03600480.jpg)">
                                                                    </div>
                            </a>
                            <div class="text_con r">
                                <a href="/read/38?mc_marking=610b2318dc116ddeaac5fecfe6b23058&amp;mc_channel=ywxqzl" target="_blank">
                                    <p class="title">JavaScript 设计模式精讲</p>
                                </a>
                                <div class="info">
                                    <span>共29小节</span>
                                    <i class="imv2-dot_samll"></i>
                                    <span>1595人已购买</span>
                                </div>
                                <div class="price_con clearfix">
                                                                            <div class="price l ">
                                            <p class="ori l">¥ 48.00</p>
                                        </div>
                                                                        <div class="btns r">
                                                                                    <a href="javascript:;" onclick="$('#js-signin-btn').click();">
                                                <div class="goBuy">马上订阅</div>
                                            </a>
                                                                            </div>
                                </div>
                            </div>
                        </li>
                                    </ul>
            </div> 
                <!-- 相关课程 -->
        <div class="related_lessons js-related_lessons">
            
        </div>
        <!-- 相关课程end -->
    </div>
</div>

<div class="js-answer-shade-pop"></div>
<div class="answer-pop answer-hidden js-answer-pop js-msg-context">
    <h3>添加回答<span class="js-close-udtiorpop imv2-close"></span></h3>
    <textarea class="answerbox" id="js-reply-editor-box"></textarea>
    <div id="js-qa-ci-footer" class="qa-ci-footer clearfix">
        <span class="qa-tips"></span>
        <div class="qa-ci-footright">
            <div class="captcha-verify-box js-answer-verify-box hide"></div>
            <button id="js-wenda-ci-submit" class="r moco-btn moco-btn-green detail-ans disabled" data-qid="555365">回答</button>
        </div>
    </div>
</div>


<div class="pop-tips-layer"></div>
<!-- 底部注册悬浮框 PM-苏Hl -->
<div class="bottom-login-box hide">
    <div class="logo-mkw"></div>
    <div class="desc-mkw">
    </div>
    <div class="logo-box">
        <!-- <a href="https://www.imooc.com/user/newsignup" class="btn register-btn">注册</a>
        <a href="https://www.imooc.com/user/newlogin" class="btn login-btn">登录</a> -->
        <a href="https://www.imooc.com/act/june2021?utm_source=shouji&utm_campaign=footips" target="_blank" class="btn register-btn">了解更多</a>
    </div>
    <span class="btn-close imv2-close js-close-login-box"></span>
    <!-- <div class="thirdpart-box">
        <div class="thirdpart-title">其他方式登录</div>
        <div class="thirdpart-item">
            <a href="https://www.imooc.com/user/newlogin" class="thirdpart-icon icon-weixin"></a>
            <a href="https://www.imooc.com/user/newlogin" class="thirdpart-icon icon-share-weibo"></a>
            <a href="https://www.imooc.com/user/newlogin" class="thirdpart-icon icon-share-qq"></a>
        </div>
    </div> -->
</div>
<div class="tipoff-block js-tipoff-block"></div>
<div class="tipoff-box js-tipoff-box">
	<div class="tipoff-top-box clearfix">
		<p class="l tipoff-title">举报</p>
		<span class="r tipoff-close-btn icon-close2 js-tipoff-close"></span>
	</div>
	<div class="tipoff-type-box js-tipoff-typebox clearfix">
		<div class="tipoff-loading">
		  	<div class="bounce1"></div>
			<div class="bounce2"></div>
			<div class="bounce3"></div>
		</div>
	</div>
	<div class="tipoff-content">
		<textarea name="tipoff-content" class="tipoff-desc js-tipoff-desc" placeholder="写下举报理由"></textarea>
		<div class="tipoff-text"><span class="js-tipoff-text">0</span>/150</div>
	</div>
	<div class="tipoff-btn-box clearfix">
		<div class="r tipoff-submit-btn js-tipoff-submit" data-tipofftype="">提交</div>
		<div class="r tipoff-cancel-btn js-tipoff-close">取消</div>
	</div>
</div>





</div>

<div id="footer" data="wenda,detail">
    <div class="waper">
        <div class="footerwaper clearfix">
            <div class="followus r">
                <a class="followus-favorites" href="javascript:;" title="收藏">
                    <span class="imv2-star1"></span>
                    <div class="favorites-tips">
                        <span class="imv2-star-revert"></span>
                        使用<b> Ctrl+D </b>可将网站添加到书签
                    </div>
                </a>
                <a class="followus-weixin" href="javascript:;" title="微信">
                    <span class="imv2-weixin11"></span>
                    <div class="flw-weixin-box"></div>
                </a>
                <a class="followus-weibo" href="http://weibo.com/u/3306361973"  target="_blank" title="新浪微博">
                    <span class="imv2-weibo11"></span>
                </a>
                <a class="followus-qzone" href="http://user.qzone.qq.com/1059809142/" target="_blank" title="QQ空间">
                    <span class="imv2-qq11"></span>
                </a>
            </div>
            <div class="footer_intro l">
                <div class="footer_link">
                    <ul>
                        <li><a href="//qiye.imooc.com" target="_blank">企业服务</a></li>
                        <li><a href="/index/sitemap.html" target="_blank">网站地图</a></li>
                        <li><a href="//www.imooc.com/" target="_blank">网站首页</a></li>
                        <li><a href="/about/us" target="_blank">关于我们</a></li>
                        <li> <a href="/about/contact" target="_blank">联系我们</a></li>
                        <li> <a href="/seek/masters" target="_blank">讲师招募</a></li>
                        <li> <a href="/help" target="_blank">帮助中心</a></li>
                        <li> <a href="/user/feedback" target="_blank">意见反馈</a></li>
                        <!--<li><a href="http://daxue.imooc.com/" target="_blank">慕课大学</a></li>-->
                        <li><a href="https://git.imooc.com" target="_blank">代码托管</a></li>
                        <!-- <li> <a href="/about/friendly" target="_blank">友情链接</a></li> -->
                       <!--  <li><a href="/corp/index" target="_blank">合作专区</a></li>
                        <li><a href="/about/us" target="_blank">关于我们</a></li> -->
                    </ul>
                </div>
                <p>Copyright © 2025 imooc.com All Rights Reserved | <a rel="nofollow" href="https://beian.miit.gov.cn/" style="color: #93999F;" target="_blank">京ICP备12003892号-11</a> <a rel="nofollow" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010802030151" style="color: #93999F;margin:0 5px;" target="_blank"><i class="beian"></i>京公网安备11010802030151号</a></p>
            </div>
        </div>
    </div>
</div>
<div id="J_GotoTop" class="elevator">
    <a href="/user/feedback" class="elevator-msg" target="_blank">
        <i class="icon-feedback"></i>
        <span class="">意见反馈</span>
    </a>
    <a href="//order.imooc.com/pay/sharegoods" class="elevator-dist" style="display: none;" target="_blank">
        <i class=""></i>
        <span class="">分销返利</span>
    </a>
    <!-- <a href="//www.imooc.com/act/invite" class="elevator-dist" target="_blank">
        <i class=""></i>
        <span class="">邀请有奖</span>
    </a> -->
    <a href="/help" class="elevator-faq" target="_blank">
        <i class="icon-ques"></i>
        <span class="">帮助中心</span>
    </a>
    <a href="//www.imooc.com/mobile/app" target="_blank" class="elevator-app" >
        <i class="icon-appdownload"></i>
        <span class="">APP下载</span>
        <div class="elevator-app-box"></div>
    </a>
    <a href="javascript:void(0)" class="elevator-weixin no-goto" id="js-elevator-weixin" >
        <i class="icon-wxgzh"></i>
        <span class="">官方微信</span>
        <div class="elevator-weixin-box"></div>
    </a>
    <a href="javascript:void(0)" class="elevator-top no-goto" style="display:none" id="backTop">
        <i class="icon-up2"></i>
        <span class="">返回顶部</span>
    </a>
</div>


<div id="globalRightFloat"></div>








<script type="text/javascript" charset="utf-8" src="/static/lib/ueditor1.4.3.1/ueditor.final.min.js?v=1.3"></script>
<script src="//moco.imooc.com/captcha/script/captcha.min.js?v=1.0"></script>

<!--script-->
<script type="text/javascript" src="/static/lib/util/error.js"></script>
<script src="/passport/static/scripts/ssologin.js?v=2.0"></script>
<script type="text/javascript" src="/static/sea-modules/seajs/seajs/2.1.1/sea.js"></script>
<script type="text/javascript" src="/static/sea_config.js?v=202501101115"></script>
<script type="text/javascript">seajs.use("/static/page/"+OP_CONFIG.module+"/"+OP_CONFIG.page)</script>

<script type="text/javascript" src="/static/page/common/dist-zhuge.js"></script>

<script type="text/javascript">seajs.use("/static/page/common/advertiseCheck.js");</script>

<script src="//moco.imooc.com/captcha/script/captcha.min.js?v=202501101115"></script>
<script>
    //动态加载advertisementReportjs

    var checkJQ = function(){
        // console.log(typeof jQuery)
       if(typeof jQuery != 'undefined') {
           clearInterval(timer);
           var scr = document.createElement('script');
           scr.type="text/javascript";
           scr.src="/static/page/common/advertisementReport.js";
           document.body.appendChild(scr);

       }
    }
    var timer = setInterval(checkJQ,1000);

</script>







<div style="display: none">
<script type="text/javascript">
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?f0cfcccd7b1393990c78efdeebff3968";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
(function (d) {
window.bd_cpro_rtid="rHT4P1c";
var s = d.createElement("script");s.type = "text/javascript";s.async = true;s.src = location.protocol + "//cpro.baidu.com/cpro/ui/rt.js";
var s0 = d.getElementsByTagName("script")[0];s0.parentNode.insertBefore(s, s0);
})(document);
</script>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</div>
</body>
</html>