2015-10-29 94 views
0

我需要將標題標記插入到我的index.html中,該標記從json中提取標題。我仍然有一個形象和鏈接。從json獲取標題標記

<a class="my-blog" id="post2" href="#"> 
     <div > 
     //title goes here 
     </div> 
and that's my javascript 




function loadBlogWidget() { 
    $.get("http://blog.lawgeex.com/wp-json/posts").done(function (cResult) { 

    for (var i = 0; i < cResult.length; i++) { 
    var cPost = cResult[i]; 
    var strLink = cPost.link; 
    var strImageSrc=cPost.featured_image.attachment_meta.sizes.thumbnail.url; 
    $("#post" + i).attr("href", strLink); 
    $("#post" + i).css("background-image", "url(" + strImageSrc + ")"); 


} 
+0

顯示您在cResult變量 –

+0

中獲得的信息嗨@Ann歡迎來到Stack Overflow,您是否可以使用任何錯誤消息更新您的問題或描述當前正在發生的事情,這將幫助我們更清楚地回答您的問題。 – BMac

+0

是的,我添加了這一行$(「#post」+ i).append('');它只是返回一個標籤的名稱。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/5502054/">nundel</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">回答</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">0<i class="fa fa-thumbs-up"></i></span> </div> <div class="post-offset"> <div class="answer fmt"> <p>我看到了json響應,它發出了一個帖子列表。我不太確定問題是否爲 1.如何更改顯示帖子列表的html的標題 或 2.如何更改用戶導航的html標題爲</p> <p>就我而言,我認爲是您的問題,您可以使用document.title = cPost.title,但是,正如我所提到的那樣,響應是一個列表,所以我假設您希望標題成爲第一篇文章的標題或東西。</p> <pre><code class="prettyprint-override"><html> <body> <a class="my-blog" id="post2" href="#"> <div > //title goes here </div> </a> </body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> function loadBlogWidget() { $.get("http://blog.lawgeex.com/wp-json/posts").done(function (cResult) { var title_changed = false; for (var i = 0; i < cResult.length; i++) { var cPost = cResult[i]; var strLink = cPost.link; var strImageSrc=cPost.featured_image.attachment_meta.sizes.thumbnail.url; $("#post" + i).attr("href", strLink); $("#post" + i).css("background-image", "url(" + strImageSrc + ")"); if(!title_changed){ document.title = cPost.title; title_changed = true; } } }); } loadBlogWidget(); </script> </html> </code></pre> <p>然而,予以警告,這是一個壞主意,因爲爬蟲將不能夠對網頁進行索引正確,因爲它不能兌現的動態名稱的更改。也許,你可以做的是有一個默認的標題,你希望抓取工具跟蹤和只有用戶的可見性有這個動態標題改變的東西。</p> <p>希望這會有所幫助!</p> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/33411379">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2015-10-29 10:13:37</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">相關問題</div> <ul class="relative_list"> <li> 1. <a href="http://hk.uwenku.com/question/p-bsvtqyba-bgn.html" target="_blank" title="Rails從HTML獲取標題標記"> Rails從HTML獲取標題標記 </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-qgcpciga-bev.html" target="_blank" title="獲取JSON對象標題"> 獲取JSON對象標題 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-zfnaqwha-bhn.html" target="_blank" title="JSON - 獲取Chrome標籤標題"> JSON - 獲取Chrome標籤標題 </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-usvhtntd-yc.html" target="_blank" title="按標題(或標記)獲取ContentControl"> 按標題(或標記)獲取ContentControl </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-rsrjjghv-eg.html" target="_blank" title="如何獲取URL「標題」標記值?"> 如何獲取URL「標題」標記值? </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-nnrqqcac-wk.html" target="_blank" title="使用DOMDocument獲取標題標記值"> 使用DOMDocument獲取標題標記值 </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-hmrdmyvd-tq.html" target="_blank" title="Google Maps Api從標記獲得標題"> Google Maps Api從標記獲得標題 </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-qdgflpvg-nu.html" target="_blank" title="從mMapView.getOverlays()獲取標記(org.osmdroid.bonuspack.overlays)"> 從mMapView.getOverlays()獲取標記(org.osmdroid.bonuspack.overlays) </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-hlrdsuva-bcn.html" target="_blank" title="從筆記本標籤獲取標籤"> 從筆記本標籤獲取標籤 </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-gmzjuwbs-ot.html" target="_blank" title="獲取標記"> 獲取標記 </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://hk.uwenku.com/question/p-dvamqfkf-boa.html" target="_blank" title="獲取JSON數據中的PHP標記?"> 獲取JSON數據中的PHP標記? </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-nregtcbg-tg.html" target="_blank" title="讀取從內部標記獲取值的XML標記"> 讀取從內部標記獲取值的XML標記 </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-ekobmvup-boe.html" target="_blank" title="從UIPanGestureRecogniser獲取UIButton標題"> 從UIPanGestureRecogniser獲取UIButton標題 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-ttmcljsf-hv.html" target="_blank" title="獲取標題從API"> 獲取標題從API </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-smllljnc-xh.html" target="_blank" title="從img標籤獲取標題"> 從img標籤獲取標題 </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-erzqnisd-ds.html" target="_blank" title="從<script>讀取JSON標記"> 從<script>讀取JSON標記 </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-psbnwoic-qu.html" target="_blank" title="獲取HTML標記"> 獲取HTML標記 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-mxntkqva-nr.html" target="_blank" title="獲得標題從JSON數據表"> 獲得標題從JSON數據表 </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-whqwprvg-bv.html" target="_blank" title="從JSON獲取值以在Google地圖上創建標記"> 從JSON獲取值以在Google地圖上創建標記 </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-bsobuoke-bbg.html" target="_blank" title="如何獲取獲取事件的標記標記信息?"> 如何獲取獲取事件的標記標記信息? </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-otcvweds-vs.html" target="_blank" title="Jsoup:從論壇獲取主題標題"> Jsoup:從論壇獲取主題標題 </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-fdvbzkbq-hb.html" target="_blank" title="獲取取消標記"> 獲取取消標記 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-zbxtmjlu-hp.html" target="_blank" title="目標C從Snapchat/Snaphax API獲取JSON"> 目標C從Snapchat/Snaphax API獲取JSON </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-ongstoap-bgr.html" target="_blank" title="Reactjs從(地理)json獲取座標"> Reactjs從(地理)json獲取座標 </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-pzaztsse-bbk.html" target="_blank" title="hHighstock從json獲取標誌數據"> hHighstock從json獲取標誌數據 </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-oqfyrrso-en.html" target="_blank" title="如何從api/sonarqube指標獲取Json?"> 如何從api/sonarqube指標獲取Json? </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-qiiankhc-se.html" target="_blank" title="如何獲得JSON標題"> 如何獲得JSON標題 </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-euqyxktr-ht.html" target="_blank" title="從移動標記獲取新位置"> 從移動標記獲取新位置 </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-wksayfst-bbs.html" target="_blank" title="從此XML文件獲取rect標記"> 從此XML文件獲取rect標記 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-pyhwiwtr-bz.html" target="_blank" title="從字符串獲取HTML標記"> 從字符串獲取HTML標記 </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048261"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新問題 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-rqxqbnet-nq.html" target="_blank" title="大熊貓 - 在同一個數據幀"> 大熊貓 - 在同一個數據幀 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-xplytjbe-mv.html" target="_blank" title="最簡單的方式分發Tensorflow培訓的前提?"> 最簡單的方式分發Tensorflow培訓的前提? </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-qumxhczl-ma.html" target="_blank" title="連接來自外部客戶端進程的kubernetes內作爲碼頭容器運行的點火服務器"> 連接來自外部客戶端進程的kubernetes內作爲碼頭容器運行的點火服務器 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-srhbjjlo-hn.html" target="_blank" title="使用Thymeleaf窗體構建POST請求"> 使用Thymeleaf窗體構建POST請求 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-psgzdntr-cy.html" target="_blank" title="如何通過控制器與MVC發送電子郵件"> 如何通過控制器與MVC發送電子郵件 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-vqbdnxxu-dt.html" target="_blank" title="替換VBA中的多個字符實例"> 替換VBA中的多個字符實例 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-dpipuaue-eo.html" target="_blank" title="node.js作爲服務移動+管理面板與角"> node.js作爲服務移動+管理面板與角 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-rrjogcxg-gg.html" target="_blank" title="平均年齡但不包括某些記錄"> 平均年齡但不包括某些記錄 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-gwigassx-bk.html" target="_blank" title="bash變量名使用變量"> bash變量名使用變量 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-mgegqkdf-cp.html" target="_blank" title="如何從Python字符串中刪除括號內的文本?"> 如何從Python字符串中刪除括號內的文本? </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 相關問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-bsvtqyba-bgn.html" target="_blank" title="Rails從HTML獲取標題標記"> Rails從HTML獲取標題標記 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-qgcpciga-bev.html" target="_blank" title="獲取JSON對象標題"> 獲取JSON對象標題 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-zfnaqwha-bhn.html" target="_blank" title="JSON - 獲取Chrome標籤標題"> JSON - 獲取Chrome標籤標題 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-usvhtntd-yc.html" target="_blank" title="按標題(或標記)獲取ContentControl"> 按標題(或標記)獲取ContentControl </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-rsrjjghv-eg.html" target="_blank" title="如何獲取URL「標題」標記值?"> 如何獲取URL「標題」標記值? </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-nnrqqcac-wk.html" target="_blank" title="使用DOMDocument獲取標題標記值"> 使用DOMDocument獲取標題標記值 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-hmrdmyvd-tq.html" target="_blank" title="Google Maps Api從標記獲得標題"> Google Maps Api從標記獲得標題 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-qdgflpvg-nu.html" target="_blank" title="從mMapView.getOverlays()獲取標記(org.osmdroid.bonuspack.overlays)"> 從mMapView.getOverlays()獲取標記(org.osmdroid.bonuspack.overlays) </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-hlrdsuva-bcn.html" target="_blank" title="從筆記本標籤獲取標籤"> 從筆記本標籤獲取標籤 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-gmzjuwbs-ot.html" target="_blank" title="獲取標記"> 獲取標記 </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://hk.uwenku.com/contact">聯系我們</a></li> <li>© 2020 HK.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>