Problem s javascript skriptom

poruka: 6
|
čitano: 1.086
|
moderatori: XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
16 godina
protjeran
offline
Problem s javascript skriptom

Što je ovdje pogrešno? 

 

// IMG Popup

if (oButtonProperties.sCode == 'img')

{

// Ask them to enter the URL of the image.

var sText = prompt(oEditorStrings['prompt_text_img'], 'http://');

if (!sText)

return;

 

// Ask them to enter the height of the image.

 

var sHeight = prompt(oEditorStrings['prompt_text_height']);

if (!sHeight || sHeight == '')

sHeight = sText; 

 

// Ask them to enter the width of the image. 

 

var sWidth = prompt(oEditorStrings['prompt_text_width']);

if (!sWidth || sWidth == '')

sWidth = sText; 

 

// Ask them to enter the alt text of the image. 

 

var sAlt = prompt(oEditorStrings['prompt_text_alt']);

if (!Alt || sAlt == '')

sAlt = sText;

 

var bbcode = '[img height=' + sHeight + 'width=' + sWidth + 'alt=' + sAlt + ']' + sText + '[/img]';

replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);

}

// Replace?

else if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null)

Moj PC  
0 0 hvala 0
17 godina
neaktivan
offline
RE: Problem s javascript skriptom

Syntax error, zadnja linija. Nedostaje blok za zadnji "if".

16 godina
protjeran
offline
Problem s javascript skriptom

To je samo dio koda. Mene zanima što ne valja u tom dijelu. 

Moj PC  
0 0 hvala 0
16 godina
neaktivan
offline
Problem s javascript skriptom

LOL?

Trebao bi početi s nečim manjim. Uzmi knjigu čitaj i radi po primjerima.

Ovako ti nema smisla programirati/učiti.

Moj PC  
0 0 hvala 0
17 godina
neaktivan
offline
RE: Problem s javascript skriptom

Odokativno, trebalo bi to malo refaktorirati.. Npr. sve varijable koje počinju sa 's' bi mogle biti jedan objekt kojeg se onda može koristit u raznim primjenama tipa "generiraj bbcode". Također, provjeru parametara prebaciti u jednu funkciju jer se svi parametri provjeravaju na jednak način. Varijabla 'Alt' vjerojatno je 'sAlt'.

Dobije se nešt poput ovog onda:

 

var s = {};// IMG Popupif (oButtonProperties.sCode == 'img') {  // Ask them to enter the URL of the image.  s.Text = prompt(oEditorStrings['prompt_text_img'], 'http://');  if (empty(s.Text)) {    return;  }  // Ask them to enter the height of the image.  s.Height = prompt(oEditorStrings['prompt_text_height']);  if (empty(s.Height)) {    s.Height = s.Text;   }  // Ask them to enter the width of the image.   s.Width = prompt(oEditorStrings['prompt_text_width']);  if (empty(s.Width)) {    s.Width = s.Text;   }  // Ask them to enter the alt text of the image.   s.Alt = prompt(oEditorStrings['prompt_text_alt']);  if (empty(s.Alt)) {    s.Alt = s.Text;  }  var bbcode = gen_bbcode(s);  replaceText(bbcode.replace(/\\n/g, '\n'), this.oTextHandle);}// Replace?else if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null) {}

function gen_bbcode (s) {  return '[img height=' + s.Height + 'width=' + s.Width + 'alt=' + s.Alt + ']' + s.Text + '[/img]';}

function empty (item) {  if (!item || (item === "")) {    return true;  }  else {    return false;  }}
Dalo bi se još po tome pošarafit, al mislim da je ovo dobar početak.

 

Poruka je uređivana zadnji put pon 3.1.2011 20:58 (Black Deus Typhon).
17 godina
moderator
online
RE: Problem s javascript skriptom
XP Master kaže...

Što je ovdje pogrešno?

Koristis alat poput NetBeansa koji te tijekom pisanja koda moze upozoriti na neke greske?

 

Dalje - koristis konzolu za greske u browseru? Nju moras koristiti za debugirranje.

1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice