Mam trochę kodu, który używa selektora w pętli.jQuery dynamiczny selektor
to działa:
document.getElementById("new_grouping_"+i).value
To nie: $("#new_grouping_"+i).value
Czy istnieje sposób to zrobić przy użyciu jQuery?
Mam trochę kodu, który używa selektora w pętli.jQuery dynamiczny selektor
to działa:
document.getElementById("new_grouping_"+i).value
To nie: $("#new_grouping_"+i).value
Czy istnieje sposób to zrobić przy użyciu jQuery?
Należy użyć val() funkcję:
var myValue = $("#new_grouping_"+i).val(); // to get the value
$("#new_grouping_"+i).val("something"); // to set the value
$("#new_grouping_"+i).val()
dostaje wartość formularza.
$("#new_grouping_"+i).text()
pobiera tekst elementu html.
$("#new_grouping_"+i).html()
dostajesz html elementu html.
$("#new_grouping_"+i).val('value')
Ustawia wartość formularza.
$("#new_grouping_"+i).text('value')
Ustawia tekst elementu html.
$("#new_grouping_"+i).html('value')
Ustawia html elementu html.
$("#new_grouping_"+i).append('value')
poprzedza coś na początku elementu $("#new_grouping_"+i).append('value')
dopisuje coś na końcu elementu
$("#new_grouping_"+i).before('value')
miejsca coś przed elementem $("#new_grouping_"+i).after('value')
miejsc czegoś po elemencie.
Zobacz więcej: jQuery Manipulation
Firefox daje mi: "$ (" # new_grouping_desc _ "+ i) .Value nie jest funkcją" kiedy dodać pusty paren po wartości –
Zaktualizowano *. Była dwie litery od rzeczywistej funkcji. –