Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][JavaScript] Długość tablicy/stringa
Fifi209
post
Post #1





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Mam taki problem, postanowiłem podszkolić się w JavaScript i chciałem do swojej strony zrobić taką "klawiaturę"

Tutaj kod całej strony + html
CODE

<html>
<head>
<title>Testy</title>
<script type="text/javascript">
function dodaj(co) {
if (co) {
document.getElementById('pole').value += co;
}else{
alert('Co mam dodać?!');
}
}

function usun(co) {
var dane = document.getElementById('pole').value;
if (dane) {
if (co) {
dane = substr(0, dane.lenght-co);
// Żadnen w komentarzu nie działa
// dane = substr(0, dane.lenght-1);
// dane = substring(0, dane.lenght-co);
// dane = substring(0, dane.lenght-1);

document.getElementById('pole').value = dane;
}else{
document.getElementById('pole').value = '';
}
}else{
alert('Co mam usunąć!?');
}
}
</script>
</head>
<body>
<center>
<table>
<tr>
<td><input type="submit" value="1" onclick="dodaj(1)"></td><td><input type="submit" value="2" onclick="dodaj(2)"></td>
<td><input type="submit" value="<-" onclick="usun(1)"></td>
</tr>
<tr>
<td><input type="submit" value="3" onclick="dodaj(3)"></td><td><input type="submit" value="4" onclick="dodaj(4)"></td>
<td><input type="submit" value="Reset" onclick="usun()"></td>
</tr>
</table>
<input type="text" id="pole" disabled="disabled">
</center>
</body>
</html>




Funkcja resetowania działa, ale jak chcę usunąć jeden znak to nic się nie dzieje...
Oczywiście dodawanie znaków działa bezproblemowo...

Ten post edytował fifi209 22.03.2009, 12:23:29


--------------------
Zainteresowania: C#, PHP, JS, SQL, AJAX, XML, C dla AVR
Chętnie pomogę, lecz zanim napiszesz: Wujek Google , Manual PHP
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




https://developer.mozilla.org/pl/Dokumentac...y/String/substr
Uzyles "funkcje" na niczym


--------------------
Go to the top of the page
+Quote Post
Fifi209
post
Post #3





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Po zmianie z:
Kod
dane = substr(0, dane.lenght-1);


na:
Kod
dane = dane.substr(0, dane.lenght-1);


Usuwa mi cały ciąg, zamiast ostatniego znaku.

W dodatku:

Kod
alert(dane.lenght);


Wyświetla:
Cytat
undefined


--------------------
Zainteresowania: C#, PHP, JS, SQL, AJAX, XML, C dla AVR
Chętnie pomogę, lecz zanim napiszesz: Wujek Google , Manual PHP
Go to the top of the page
+Quote Post
wookieb
post
Post #4





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Kod
dane.length


--------------------
Go to the top of the page
+Quote Post
Fifi209
post
Post #5





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Cytat(wookieb @ 22.03.2009, 12:15:53 ) *
Kod
dane.length


Dzięki bardzo ("pomógł" 2x), jestem jednak debil. ;d
ctr+c ctr+v jak widać nie dobra metoda. Bo raz strzeliłem literówkę i tak zostało. ;d


--------------------
Zainteresowania: C#, PHP, JS, SQL, AJAX, XML, C dla AVR
Chętnie pomogę, lecz zanim napiszesz: Wujek Google , Manual PHP
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 04:29