質問

I have a jsp variable "tagList" which contains a list of Tags (CQ5 Tags). This list needs to be displayed in a dropdown.

Since I have to use AJAX on change of the dropdown, I need to use jquery to iterate through "tagList" and display all tag titles in the dropdown.

Is it even possible ?

I tried a basic code but it alerts only "undefined".

$("#tagList").each(function(index) {
alert( index + ": " + $(this).title);
});
役に立ちましたか?

解決

If I understand correctly, you're building a select list with JSP Is this true? If so, then to iterate thru the list is fairly easy:

$("#taglist option").each(function(idx, val){
    alert(idx + " : " + $(this).val());
});

Find a fiddle here: http://jsfiddle.net/richbuff/7tBAd/

Keep in mind that jQuery doesn't know about JSP tags. JavaScript (and thus jQuery) only knows about HTML and the DOM.

Hope this helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top