Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JQuery] metoda find na dynamicznej treści
melior
post
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 3
Dołączył: 7.12.2009

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


Mam kod, który wyłapuje mi inputy z klasami integer lub string.

Kod
var element = $( form ).find(".integer, .string");


To działa ślicznie, do momentu, gdy nie dodam jakiegoś inputa poprzez metodę .html().

O ile w internecie jest milion przykładów dla click, jeżeli chodzi o wykorzystanie metod on, delegate, live w tego typu sytuacjach, to nie mogę dojść jak to okodować z find.
Ktoś pomoże?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
melior
post
Post #2





Grupa: Zarejestrowani
Postów: 68
Pomógł: 3
Dołączył: 7.12.2009

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


Na prostym przykładzie rzeczywiście działa, ale zamiana html() na append() nie pomogła.

Mam coś takiego:

Kod
<form id="search_form'" action="" method="POST">
//basic data
<input type="text" name="data1" value=""/>
<input type="text" name="data2" value=""/>
//additional data
<input type="text" class="input string" name="otherData1" value=""/>
<input type="text" class="input string" name="otherData2" value=""/>
<input type="text" class="input integer" name="otherData3" value=""/>
<input type="text" class="input integer" name="otherData4" value=""/>
<input type="button" value="send" />
//place to put extra data from AJAX response
<div id="content"></div>
</form>



Kod
var handler = $('#search_form');

function validObligatoryAndType(handler){
    handler.submit(function(event){
        clearExceptions(handler);
        var valid = checkForm(handler);
        if(valid){
            return true;
        }
        else{
            return false;
        }
    });
}

validObligatoryAndType(handler);

function checkForm(form){
var element = $( form ).find(".integer, .string");
var valid = true;
$.each(element, function(key, val){
... //validation
});
return valid;
}

+ funkcja, które pobiera z odpowiedzi AJAX dane i generuje z nich dodatkowe pola input:

propInputs = '...'; // pola input
if(propInputs != ''){propInputs = '<br>Właściwości wybranej kategorii:<br><br><table><tbody>'+propInputs+'</tbody></table>';}
$('#content').append(propInputs);
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 7.10.2025 - 13:38