2011-03-07 6 views
0

<div class="ms-vb itx">에서 URL을 가져오고 아래 범위 내의 href로 바꾸고 싶습니다. 그게 Jquery에서 할 수 있을까요? 그 의미가 있습니까?jquery div에서 URL을 가져 와서 span에 삽입하십시오.

url = $('.ms-vb a').attr('href'); 
$('#your_span_id a').attr('href', url); 

그러나 당신은 당신의 divspan, 예를 식별 할 수있는 방법이 있어야합니다

<td height="100%" class="ms-vb-title ms-vb-lastCell" onmouseover="OnChildItem(this)"> 
<div eventtype="" perm="0x7fffffffffffffff" field="LinkTitle" id="5" ctxname="ctx6" onmouseover="OnItem(this)" class="ms-vb itx"> 
<a target="_self" onclick="EditLink2(this,6);return false;" href="/_layouts/RF.Portal.Web/DetailActualite.aspx?4&amp;ListId={5B770E71-5269-4F45-87A0-2DEFA1136E40}&amp;ID=5&amp;ContentTypeID=0x0100FBEA8B5F8E1448F4B48C33A18522E2DA01001677EA3C9B9802408D15440E3B1906DE" onfocus="OnLink(this)">icitait l'honneur d'être reçu,</a> 
<img class="ms-newgif" title="Nouveau" alt="Nouveau" src="/_layouts/1036/images/new.gif"> 
</div> 
<div onmouseover="OnChildItem(this.parentNode); return false;" class="s4-ctx" style="top: 52px; left: 1015px; height: 105px; line-height: 105px; margin: 0px;"> 
<span>&nbsp;</span> 
<a title="Menu Ouvrir" href="javascript:;" onclick="PopMenuFromChevron(event); return false;" onfocus="OnChildItem(this.parentNode.parentNode); return false;"> 
<img style="visibility: hidden;" src="/_layouts/images/ecbarw.png" alt="Menu Ouvrir"></a> 
<span>&nbsp; 
</span> 
</div> 
<span style="color: rgb(128, 128, 128);"><em> 
      Publié le 07/03/2011 11:30 - 
      En cours</em></span><br> et ayant nom Athos, Porthos et Aramis. Nous l'avouons, ces trois noms étrange<br><br> 
      <span style="font-size: 0.9em; color: rgb(128, 128, 128);" id="lireArticle"> 
      <a class="rfr-link-action" href="DispForm.aspx?ID=5">Lire l'article</a> 
     <br><br></span> 
     </td> 
+0

URL을 가져올 div를 어떻게 식별합니까? –

+0

클래스 ms-vb itx – user472285

답변

3

물론, 올바른 요소를 선택했는지 확인해야합니다.

예 :

var $div = $('div.ms-vb.itx'); 
$div.next('span').find('a').attr('href', $div.find('a').attr('href')); 

당신은이 클래스와 더 많은 요소가 있고 그들 모두에 대해이 작업을 수행하려면, 당신이 사용할 수있는 each() :

$('div.ms-vb.itx').each(function() { 
    $(this).next('span').find('a').attr('href', $(this).find('a').attr('href')); 
}); 

업데이트 :

좋아요, 당신이 테이블에 이것들을 여러 개 가지고 있다고 가정하고 싶습니다. 그들 모두를위한 것입니다.

변경하려는 a 요소의 클래스는 rfr-link-action 인 것 같습니다.이를 사용하면됩니다. 참고로, span 요소에는 ID가 있지만 ID는 문서에서 고유해야합니다. 두 개의 요소가 동일한 ID를 가질 수는 없습니다.

$('div.ms-vb.itx').each(function() { 
    $(this).closest('td') // gets a reference to the table cell 
    .find('a.rfr-link-action') // finds the link 
    .attr('href', $(this).find('a').attr('href')); // sets the URL 
}); 
+0

가 작동하지 않습니다. (TypeError : $ (".ms-vb")가 null입니다. – user472285

+0

@ user472285 : 저의 작품 : http://jsfiddle.net/z8ZVU/ 마크 업이 다를 수 있습니다. 작동하지 않거나 다른 곳에서 오류가 있습니다. 웹 사이트에 대한 링크를 제공 할 수 있습니까? –

+0

hmmm, 이상한! – user472285

0

이 시도 id 속성 또는 smth를 추가하십시오.

+0

에 의해 작동하는 것 같습니다 :) 어떻게 그 페이지의 모든 div에 적용 할 것이라고? .eachfunction처럼? – user472285

관련 문제