簡體   English   中英

如何重定向或鏈接到另一個頁面的DIV元素內的URL?

[英]How to Redirect or Link to a URL Inside Another Page's DIV Element?

我在Sharepoint上有一個頁面設置,具有四個不同的鏈接,這些鏈接下的描述不斷變化。 現在,我有了每個鏈接的標題以及從另一個頁面(一個.aspx文章頁面)提取的每個鏈接的描述,我的同事們可以輕松地對其進行更新。 因此,當他們更新文章時,jquery會更新所有四個鏈接的標題和描述。 我的問題是要獲取實際的URL目標(href),以從同事的文章頁面上的div更新。 我可以找到的用於更改href的所有代碼都使用.attr來完成類似的操作,但在我發現的所有示例中,都需要在代碼中放入新的url。 每當他們更改文章時,此URL都會更改。 有任何想法嗎? (我不是編碼員,而是具有一點HTML和Javascript知識的平面設計師)

首先是腳本:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#CI1").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI1.aspx #newstitle");
$("#CI1b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI1.aspx #newsbody");
$("#CI2").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI2.aspx #newstitle");
$("#CI2b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI2.aspx #newsbody");
$("#CI3").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI3.aspx #newstitle");
$("#CI3b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI3.aspx #newsbody"); 
$("#CI4").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI4.aspx #newstitle");
$("#CI4b").load("http://jfghome/CorpInitiatives/Pages/Corporate%20Initiatives/CI4.aspx #newsbody"); 
$("#pCI1").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image1.png");
$("#pCI2").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image2.png");
$("#pCI3").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image3.png");
$("#pCI4").attr('src',"http://jfghome/CorpInitiatives/PublishingImages/Image4.png");
});
</script>    

現在是HTML(順便說一句,這些不再是APDivs,我更改了它們的CSS屬性):

<div id="Col2">
<div id="apDiv5">
<div id="apDiv8"><a href="/CorpInitiatives/MOR/SitePages/Home.aspx"><img id="pCI1" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="1" /></a></div>
<div id="apDiv10"><strong><a href="/CorpInitiatives/MOR/SitePages/Home.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI1">Loading...</div></a></strong>
<div id="CI1b">...</div></div>
</div>
<div id="apDiv3">
<div id="apDiv9"><a href="/CorpInitiatives/SitePages/JFGHomeInfo.aspx"><img id="pCI2" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="2" /></a></div>
<div id="apDiv11"><strong><a href="/CorpInitiatives/SitePages/JFGHomeInfo.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI2">Loading...</div></a></strong><div id="CI2b">
...</div></div>
</div>
<div id="apDiv2">
<div id="apDiv12"><strong><a href="/resources/TalkingPoints/SitePages/Scorecard.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI3">Loading...</div></a></strong>
<div id="CI3b">...</div></div>
<div id="apDiv13"><a href="/resources/TalkingPoints/SitePages/Scorecard.aspx"><img id="pCI3" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="3" /></a></div>
</div>
<div id="apDiv6">
<div id="apDiv14"><strong><a href="/CorpInitiatives/Pages/townhallrecap2013.aspx" style="color:#324c71; font-size:16px; font-family: Cambria, Hoefler Text, Liberation Serif, Times, Times New Roman, serif; font-size:18px"><div id="CI4">Loading...</div></a></strong>
<div id="CI4b">...</div></div>
<div id="apDiv15"><a href="/CorpInitiatives/Pages/townhallrecap2013.aspx"><img id="pCI4" src="/CorpInitiatives/SiteAssets/SitePages/Home%20Testing/ajax-loader100x70.gif" width="100" height="70" alt="4" /></a></div>
</div>
</div>

因此,除了從我的同事文章中的div中獲取URL並將其放置在我頁面的href中之外,這一切都可行。 請幫忙! 所有建議,不勝感激。

我想我不太了解您的所有問題,我想您是在問如何重定向或鏈接到另一個頁面內的div?

如果是,請在URL末尾添加此#{div_id},在鏈接末尾和div id之間沒有空格,希望這對您有所幫助

如果我對您的理解正確,那么會有另一個頁面包含鏈接,並且您希望將鏈接中的內容加載到頁面中。

這樣的事情行嗎?

mainPage.html

<script>
$(document).ready(function() {
    $('#mainDiv').load('pageToLoadLinkFrom.html', function() {
        $('#mainDiv').load($(this).find('#specialLink a').attr('href'))
    })
})
</script>

...

<body>
  <div id="mainDiv" />
</body>

接着...

pageToLoadLinkFrom.html

<body>
  <div id='specialLink'><a href="someOtherPage.html">Some Other Page</a></div>
</body>

其他頁面中的href in鏈接包含指向該頁面的相對鏈接。 從頁面中,如果要使用這些鏈接,則需要確保頁面與目標服務器在同一服務器中的目錄位於同一目錄下,或者獲取目標頁面的window.location。 然后,您可以構造一個絕對URL,以便可以使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM