Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: problem z kodem JS
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
zew2
Witam
Znalazłem taki kod na necie który miał obsłużyć mi tagi bbcode ale coś nie działa ,a w javie jestem troche zielony moglibyście sprawdzić co jest nie tak

  1. // Tworzymy obiekt BBcode
  2. var bbcode = new BBcode();
  3.  
  4. function BBcode() {
  5.  
  6. // LISTA ATRYBUTOW KLASY
  7. var input;
  8. var start;
  9. var stop;
  10. var buttonPrefix;
  11. var tagi;
  12.  
  13. // LISTA METOD KLASY
  14. var zaznacz;
  15. var naPoczatek;
  16. var naKoniec;
  17. var naPozycje;
  18. var tag;
  19.  
  20.  
  21. }
  22.  
  23.  
  24. // POCZATEK KONSTRUKTORA KLASY
  25. this.buttonPrefix = 'bb_';
  26. this.tagi = new Array();
  27. // KONIEC KONSTRUKTORA KLASY
  28.  
  29. this.zaznacz = function() {
  30. if (this.input.setSelectionRange)
  31. {
  32. this.input.focus();
  33. this.input.setSelectionRange(this.start, this.stop);
  34. }
  35. else if(this.input.createTextRange)
  36. {
  37. var zasieg = this.input.createTextRange();
  38. zasieg.collapse(true);
  39. zasieg.moveEnd('character', this.stop);
  40. zasieg.moveStart('character', this.start);
  41. zasieg.select();
  42. }
  43. }
  44.  
  45.  
  46. this.naPoczatek = function() {
  47. this.start = 0;
  48. this.stop = 0;
  49. this.zaznacz();
  50. this.input.focus();
  51. }
  52.  
  53. this.naKoniec = function(mod) {
  54. this.start = this.input.value.length;
  55. this.stop = this.input.value.length;
  56. this.zaznacz();
  57. if(mod==true) this.input.scrollTop = this.input.scrollHeight;
  58. this.input.focus();
  59. }
  60.  
  61. this.naPozycje = function(pozycja) {
  62. this.start = pozycja;
  63. this.stop = pozycja;
  64. this.zaznacz();
  65. this.input.focus();
  66. }
  67.  
  68. this.tag = function(tag,mod) {
  69. tag = tag.toLowerCase();
  70. var adres = '';
  71. var starttag = tag;
  72. var stoptag = '/'+tag;
  73. var t1 = '';
  74. var t2 = '';
  75. if (this.input.setSelectionRange) {
  76. this.start = this.input.selectionStart;
  77. this.stop = this.input.selectionEnd;
  78. if(this.start!=this.stop) {
  79. var tekst = this.input.value.substring(this.start,this.stop);
  80. if(tekst.substring(0,7)=='http://' && mod==true) {
  81. starttag = tag+'='+tekst;
  82. }
  83. else {
  84. if(mod==true && this.tagi[tag]!=1) {
  85. var adres = prompt("Podaj adres (z http://):","http://");
  86. var adres = '='+adres;
  87. }
  88. starttag = tag+adres;
  89. stoptag = '/'+tag;
  90. }
  91. t1 = this.input.value.substring(0,this.start);
  92. t2 = this.input.value.substring(this.stop,this.input.value.length);
  93. this.input.value = t1+'['+starttag+']'+tekst+'['+stoptag+']'+t2
  94. this.naKoniec(true);
  95. }
  96. else {
  97. var button = document.getElementById(this.buttonPrefix+tag);
  98. if(this.tagi[tag]==1) {
  99. this.tagi[tag] = 0;
  100. button.value = button.value.substring(0,button.value.length-2);
  101. tag = stoptag;
  102. }
  103. else {
  104. this.tagi[tag] = 1;
  105. if(mod==true) {
  106. var adres = prompt("Podaj adres (z http://):","http://");
  107. var adres = '='+adres;
  108. }
  109. tag = tag+adres;
  110. button.value = button.value+' *';
  111. }
  112. var t1 = this.input.value.substring(0,this.start);
  113. var t2 = this.input.value.substring(this.stop, this.input.value.length);
  114. this.input.value = t1+'['+tag+']'+t2
  115. this.naKoniec();
  116. }
  117. }
  118. else if (document.selection) {
  119. alert('badzIEw');
  120. }
  121. }


a tu jest kod formularza i pola które obsługujemy

  1. <form action="" method="post">
  2.  
  3. <input type="button" id="bb_b" onclick="zamien(this.form.tresc,'b');" value="B" />
  4. <input type="button" id="bb_i" onclick="zamien(this.form.tresc,'i');" value="I" />
  5. <input type="button" id="bb_u" onclick="zamien(this.form.tresc,'u');" value="U" />
  6. <input type="button" id="bb_obraz" onclick="zamien(this.form.tresc,'obraz',true);" value="Obraz" />
  7. <input type="button" id="bb_link" onclick="zamien(this.form.tresc,'link',true);" value="Link" />
  8. <br /><textarea name="tresc">Forumweb testuje klase BBcode</textarea>
  9. </form>


Z góry dzięki za wszystko
thek
Czy Ty wiesz do czego odnosi się obiekt this? Bo na pewno nie do całej strony/dokumentu/formularza smile.gif
zew2
Dlatego napisałem że jestem zielony z JS wstydnis.gif
ale w onclick masz podane "this.form.tresc"
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.