2013-06-05 43 views
0

頁面的標題我在點擊鏈接的href使用​​一樣加載頁面的內容如下:獲取裝載.load

$("html").on('click', 'a', function(event) { 
    event.preventDefault(); // obviously 
    var url = this.href + " #main"; // holds the content of #main at a given url 
    $('#ajax-container').load(url); // loads that content into #ajax-container 
    document.title = "?"; 
}); 

我怎麼能搶加載的頁面,並顯示的標題它?

+0

' $('title')。html()'或'$('title')。text()'應該這樣做 –

+0

如果只加載'#main'中的內容,返回的數據將不包含'元素(除非你有它在'#main'裏面) - 這意味着你很可能無法像以上那樣獲得它。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/921204/">techfoobar</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">3<i class="fa fa-thumbs-up"></i></span> <i class="fa fa-check fa-2x"></i> </div> <div class="post-offset"> <div class="answer fmt"> <p>試試這個可能:</p> <pre><code class="prettyprint-override">var url = this.href; //following techfoobar's comment $('#ajax-container').load(url,function(data){ document.title = $($.trim(data)).find('title').text();//$.trim() used for old IE to move unexpected characters }); </code></pre> <p>但是,你不會騎上你所期望的內容<code class="prettyprint-override">$('#ajax-container')</code></p> <p>所以使用$獲得()代替:</p> <pre><code class="prettyprint-override">var url = this.href; //following techfoobar's comment $.get(url,function(data){ document.title = $('<div/>').html($.trim(data)).find('title').text(); $('#ajax-container').html($('<div/>').html($.trim(data)).find('body').html()); }); </code></pre> </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/16945923">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2013-06-05 17:10:07</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">對於IE compat信息+1。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/921204/">techfoobar</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">嗨@roasted。試過了,什麼都沒有發生。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2448079/">KeithRules</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">使用$ .get() – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </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-nayftina-su.html" target="_blank" title="獲取裝載形式PHP"> 獲取裝載形式PHP </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-qfvwmzvg-dg.html" target="_blank" title=".load()在HTM裝載HTM與參數"> .load()在HTM裝載HTM與參數 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-ooybxbss-bms.html" target="_blank" title="jQuery的ajax的load方法裝載"> jQuery的ajax的load方法裝載 </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-zulznicx-bgy.html" target="_blank" title="獲取jQuery $ .load()ajax對象"> 獲取jQuery $ .load()ajax對象 </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-ofqroyky-kt.html" target="_blank" title="獲取.load函數以在加載的內容中工作"> 獲取.load函數以在加載的內容中工作 </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-gohtqxnq-wn.html" target="_blank" title="jQuery AJAX Load:從加載的文檔中獲取變量"> jQuery AJAX Load:從加載的文檔中獲取變量 </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-aekslpvk-de.html" target="_blank" title="從外部裝載的swf獲取裝載機的孩子"> 從外部裝載的swf獲取裝載機的孩子 </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-bxygbnay-bgq.html" target="_blank" title="mapit地圖 - 裝載數據獲取GEOSException"> mapit地圖 - 裝載數據獲取GEOSException </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-dsthmfmi-ku.html" target="_blank" title=".load獲取頁面,但不顯示"> .load獲取頁面,但不顯示 </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-bsynwfqr-us.html" target="_blank" title="如何獲取.load()的源代碼"> 如何獲取.load()的源代碼 </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-kwhdxqvn-xo.html" target="_blank" title="jQuery .load() - 從DOM中獲取td內容"> jQuery .load() - 從DOM中獲取td內容 </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-khenlibs-nu.html" target="_blank" title="如何使用LOAD DATA LOCAL INFILE裝載數量?"> 如何使用LOAD DATA LOCAL INFILE裝載數量? </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-fhsntjwd-oh.html" target="_blank" title="LOAD DATA LOCAL INFILE裝載僅有一條記錄"> LOAD DATA LOCAL INFILE裝載僅有一條記錄 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-kssftkoq-wr.html" target="_blank" title="如何等待裝載jQuery的.load()函數"> 如何等待裝載jQuery的.load()函數 </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-tenigdcn-zs.html" target="_blank" title=".mouseenter()對裝載了jQuerys .load()函數的內容不起作用"> .mouseenter()對裝載了jQuerys .load()函數的內容不起作用 </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-uujihcxt-xt.html" target="_blank" title="獲取文件下載對話框,而不是裝載頁面"> 獲取文件下載對話框,而不是裝載頁面 </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-bxwyozfk-wz.html" target="_blank" title="在我的瀏覽器上獲取{%load chartit%}。圖表未使用圖表加載"> 在我的瀏覽器上獲取{%load chartit%}。圖表未使用圖表加載 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-pwxrsckh-baa.html" target="_blank" title="如何獲取所有使用jQuery加載的HTML部分的Javascript工作.load()"> 如何獲取所有使用jQuery加載的HTML部分的Javascript工作.load() </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-blmzcgro-br.html" target="_blank" title="JQuery .load()不會加載html"> JQuery .load()不會加載html </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-hgkfbxar-bdw.html" target="_blank" title="jQuery .load()不加載插件"> jQuery .load()不加載插件 </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-mcfszsot-wt.html" target="_blank" title="DomDocument-> load()未加載.plist"> DomDocument-> load()未加載.plist </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-amldhahe-dd.html" target="_blank" title="load()未加載頁面"> load()未加載頁面 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-mcjvgqff-bca.html" target="_blank" title="JQuery .load()不加載類"> JQuery .load()不加載類 </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-qtqoewdm-pk.html" target="_blank" title="CakePlugin :: load('Facebook');未加載"> CakePlugin :: load('Facebook');未加載 </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-feyfzddc-wv.html" target="_blank" title="的JQuery load()函數重載"> 的JQuery load()函數重載 </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-qxfmamyk-bcx.html" target="_blank" title="Android從eclipse下載SDK獲取讀取超時沒有安裝"> Android從eclipse下載SDK獲取讀取超時沒有安裝 </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-qnntftjq-zq.html" target="_blank" title="停止從加載.load加載"> 停止從加載.load加載 </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-qkpzzcfk-tt.html" target="_blank" title="卸載加載Loader :: load()的swfs"> 卸載加載Loader :: load()的swfs </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-fqfvncyk-oe.html" target="_blank" title="jQuery的.load()使用.load功能不加載HTML註釋標記"> jQuery的.load()使用.load功能不加載HTML註釋標記 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-piwqvzhq-bhu.html" target="_blank" title="如何使用javascript加載函數兩次? (load in load)"> 如何使用javascript加載函數兩次? (load in load) </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-xcczrhnn-bmd.html" target="_blank" title="我無法找到該錯誤不可識別規則中的溶液"> 我無法找到該錯誤不可識別規則中的溶液 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-tlpgxqll-bkr.html" target="_blank" title="在SQL中嵌套計數"> 在SQL中嵌套計數 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-hnidqfks-bdt.html" target="_blank" title="爲什麼解組指針變量不可能?"> 爲什麼解組指針變量不可能? </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-ysadvwzz-bep.html" target="_blank" title="JavaFX綁定和屬性更改"> JavaFX綁定和屬性更改 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-ybbpalav-bgc.html" target="_blank" title="C#查找控制,鑄造,優雅代碼"> C#查找控制,鑄造,優雅代碼 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-uvbjcdmw-bev.html" target="_blank" title="WordPress的不同的圖像大小"> WordPress的不同的圖像大小 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-srmimdor-bgm.html" target="_blank" title="我的納稅風格與過濾器不工作"> 我的納稅風格與過濾器不工作 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-hoziwpbv-bgs.html" target="_blank" title="laravel檢查,如果集合包含模型"> laravel檢查,如果集合包含模型 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-dmnzbvgn-bmt.html" target="_blank" title="標籤中的EditText"> 標籤中的EditText </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-htlgjbzn-bmn.html" target="_blank" title="正則表達式從字符串中獲取數組編號"> 正則表達式從字符串中獲取數組編號 </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-nayftina-su.html" target="_blank" title="獲取裝載形式PHP"> 獲取裝載形式PHP </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-qfvwmzvg-dg.html" target="_blank" title=".load()在HTM裝載HTM與參數"> .load()在HTM裝載HTM與參數 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-ooybxbss-bms.html" target="_blank" title="jQuery的ajax的load方法裝載"> jQuery的ajax的load方法裝載 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-zulznicx-bgy.html" target="_blank" title="獲取jQuery $ .load()ajax對象"> 獲取jQuery $ .load()ajax對象 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-ofqroyky-kt.html" target="_blank" title="獲取.load函數以在加載的內容中工作"> 獲取.load函數以在加載的內容中工作 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-gohtqxnq-wn.html" target="_blank" title="jQuery AJAX Load:從加載的文檔中獲取變量"> jQuery AJAX Load:從加載的文檔中獲取變量 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-aekslpvk-de.html" target="_blank" title="從外部裝載的swf獲取裝載機的孩子"> 從外部裝載的swf獲取裝載機的孩子 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-bxygbnay-bgq.html" target="_blank" title="mapit地圖 - 裝載數據獲取GEOSException"> mapit地圖 - 裝載數據獲取GEOSException </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-dsthmfmi-ku.html" target="_blank" title=".load獲取頁面,但不顯示"> .load獲取頁面,但不顯示 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-bsynwfqr-us.html" target="_blank" title="如何獲取.load()的源代碼"> 如何獲取.load()的源代碼 </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>