Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z jquery ('#div').show
Forum PHP.pl > Forum > Po stronie przeglądarki
ir3nicus
Witam, mam nastepujacy skrypt:

  1.  
  2.  
  3. <title>TEST SLIDERA</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  5. <meta name="author" content="lukasz_os" >
  6. <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
  7. <script type="text/javascript">
  8. function rotate(){
  9. last=$("#container .news").index($('.news:last')[0]);
  10. ind=$("#container .news").index($('.news:visible')[0]);
  11. $('.news').eq(ind).hide();
  12. if(ind==last){
  13. ind="0";
  14. }
  15. else
  16. {
  17. ind++;
  18. }
  19. $('.news').eq(ind).show();
  20. }
  21. $().ready(function(){
  22. $('#container .news:first').show();
  23. var inter = setInterval("rotate()",2000);
  24.  
  25.  
  26. $(".tit").click(function() {
  27.  
  28. clearInterval(inter);
  29.  
  30.  
  31. var href = $(this).attr("href");
  32.  
  33. $('.tit').css('background-color', 'white');
  34. $(this).css('background-color', 'green');
  35. $('.news').hide();
  36. $(href).show();
  37. return false;
  38. });
  39.  
  40. });
  41. <style type="text/css">
  42. * {
  43. margin:0;
  44. padding:0;
  45. }
  46. body {
  47. background:#ffffff;
  48. color:#000;
  49. }
  50. .news {
  51. width:300px;
  52. height:200px;
  53. border:1px solid #000;
  54. display:none;
  55. }
  56. #container {
  57. margin:20px;
  58. width:302px;
  59. height:202px;
  60. }
  61. </head>
  62.  
  63. <div id="container">
  64. <div class="news" id="#n1" style="background-color:red;">
  65. div 1ijiojiji
  66. </div>
  67. <div class="news" id="#n2" style="background-color:green;">
  68. div 2joijioj
  69. </div>
  70. <div class="news" id="#n3" style="background-color:black;">
  71. div 3iojioj
  72. </div>
  73. <div class="news" id="#n4" style="background-color:yellow;">
  74. div 4iojioj
  75. </div>
  76. </div>
  77.  
  78. <a class="tit" href='#n1'>1</a>
  79. <a class="tit" href='#n2'>2</a>
  80. <a class="tit" href='#n3'>3</a>
  81. <a class="tit" href='#n4'>4</a>
  82.  
  83.  
  84. </body>
  85. </html>


Jednakze po kliknieciu przycisku div o id "href" sie nie wyswietla czy ktos wie czemu ?
nospor
nie: id="#n1"
a: id="n1"
ir3nicus
omg thx

jeszcze takie pytanie: jak wyciagnać atrybut 'rel' z linka o podanym atrybucie 'href' ?


Chce zmienić tło przy intervalu

[..]

ind=$(".promo .bo1").index($('.bo1:visible')[0]);
indPrzycisk = '#promo'+c;


/// imgPath = $('href[indPrzycisk]').attr('rel'); --- to nie dziala

$('.advert').css('background-image', 'url("' + imgPath +'")');

[..]
nospor
Co to ma niby oznaczac:
$('href[indPrzycisk]')
?
Może pokaż jak ten link wygląda, bo z tego zapisu nic nie kumam
ir3nicus
  1. <span class="advert" style="background: url('../admin/offerPhotos/<?= $d[0]['id_offer']; ?>/thumbs/<?= $d[0]['mainPhoto']; ?>');";>
  2. <span class="promo">
  3.  
  4. <a class="tit" style="background-color:#FF7B00" rel="../admin/offerPhotos/<?= $d[0]['id_offer']; ?>/thumbs/<?= $d[0]['mainPhoto']; ?>" href='#promo1'>1</a>
  5. <a class="tit" rel="../admin/offerPhotos/<?= $d[1]['id_offer']; ?>/thumbs/<?= $d[1]['mainPhoto']; ?>" href='#promo2'>2</a>
  6. <a class="tit" rel="../admin/offerPhotos/<?= $d[2]['id_offer']; ?>/thumbs/<?= $d[2]['mainPhoto']; ?>" href='#promo3'>3</a>
  7. <a class="tit" rel="../admin/offerPhotos/<?= $d[3]['id_offer']; ?>/thumbs/<?= $d[3]['mainPhoto']; ?>" href='#promo4'>4</a>
  8.  
  9.  
  10.  
  11. <span class="bo1" id="promo1" ><a href="oferta/<?= $d[0]['id_offer']; ?>/<?= Utils::getLinkForm($d[0]['title']); ?>"><?= UtilsHTML::trunc($d[0]['title'], 40); ?></a></span>
  12. <span class="bo1" id="promo2" style="display:none";><a href="oferta/<?= $d[1]['id_offer']; ?>/<?= Utils::getLinkForm($d[1]['title']); ?>"><?= UtilsHTML::trunc($d[1]['title'], 40); ?></a></span>
  13. <span class="bo1" id="promo3" style="display:none";><a href="oferta/<?= $d[2]['id_offer']; ?>/<?= Utils::getLinkForm($d[2]['title']); ?>"><?= UtilsHTML::trunc($d[2]['title'], 40); ?></a></span>
  14. <span class="bo1" id="promo4" style="display:none";><a href="oferta/<?= $d[3]['id_offer']; ?>/<?= Utils::getLinkForm($d[3]['title']); ?>"><?= UtilsHTML::trunc($d[3]['title'], 40); ?></a></span>
  15.  
  16.  
  17. </span>
  18. </span>
nospor
No i skąd ci się wzięło to:
$('href[indPrzycisk]')
? No nijak nie wychodzi

imgPath = $('a.tit').attr('rel');
ir3nicus
Chciałem szukać po hrefie anolognicznie jak w tym linku: http://api.jquery.com/has-attribute-selector/ po divie. Bo potrzebuje żeby brać rela z linka o kolejnym ID w Intervalu.
Cały kod:


  1.  
  2.  
  3. function rotate(){
  4. last=$(".promo .bo1").index($('.bo1:last')[0]);
  5. ind=$(".promo .bo1").index($('.bo1:visible')[0]);
  6.  
  7. //ind2= $(".promo .tit").index($('.tit:visible'[0]);
  8.  
  9. var c = parseInt(ind)+1;
  10. indPrzycisk = '#promo'+c;
  11.  
  12. // console.log(indPrzycisk);
  13. // imgPath = $('href[indPrzycisk]').attr('rel');
  14. // console.log(imgPath);
  15.  
  16.  
  17. //imgPath = $('a.tit').attr("rel");
  18. //$('.advert').css('background-image', 'url("' + imgPath +'")');
  19. $('.bo1').eq(ind).hide();
  20. $('.tit').eq(ind).css('background-color', '#000');
  21.  
  22. if(ind==last){
  23. ind="0";
  24. }
  25. else
  26. {
  27. ind++;
  28. }
  29. $('.bo1').eq(ind).show();
  30. $('.tit').eq(ind).css('background-color', '#FF7B00');
  31. }
  32.  
  33.  
  34. $(document).ready(function()
  35. {
  36.  
  37.  
  38. var inter = setInterval("rotate()",2000);
  39.  
  40. $(".tit").click(function() {
  41.  
  42. clearInterval(inter);
  43.  
  44. var href = $(this).attr("href");
  45. var imgPath = $(this).attr("rel");
  46. $('.advert').css('background-image', 'url("' + imgPath +'")');
  47. $('.tit').css('background-color', "#000");
  48. $(this).css('background-color', "#FF7B00");
  49. $('.bo1').hide();
  50. $(href).show();
  51.  
  52. return false;
  53.  
  54. });
  55. }
nospor
Ty mi nie podawaj linka do atrybutów bo ja wiem jak to działa. Tłumaczę Ci że ty kod wziąłeś z kosmosu...
Nie masz żadnego elementu HREF (owszem, jest ale on się nazywa A a nie HREF) oraz tym bardziej nie masz elementu który ma atrybut o nazwie "indPrzycisk"

Kapisz?

Ech... znaj litość Pana... wink.gif
Kod
imgPath = $('a[href="'+indPrzycisk+'"]').attr('rel');
ir3nicus
no tak teraz rozumiem. Tylko nadal nie mam pomysłu jak ja mam wycignac tego "rela"...

ok . dzieki
mat-bi
Nie no...

nospor podał ci, jak przypisać do zmiennej wartość rel danego linku, a ty dalej nie rozumiesz?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.