i have a picklist its name is new_tarif开发者_运维百科f and i want to add values to picklist onload using js or jquery.How can i do it ?
document.onLoad(function(){
$(#new_tariff).append(" VALUES TO BE APPENDED ");
});
This assumes new_tariff
is set to id="new_tariff"
. Replace the #
with a .
if you're using a class. These are much simpler than a name: $.prop("name", "new_tariff")
(http://api.jquery.com/prop/).
FYI there is $.prepend()
which does almost exactly the same thing as append, except it adds it to the beginning instead of the end.
It would probably be better to have some default value(s) that you replace onLoad in case the onLoad fails. To do this you would use $.html()
to replace the default values with the ones from onLoad. (you can also store the values externally and do an $.ajax()
call to $.load()
them in, but this is more complicated.
精彩评论