简体   繁体   English

Jquery迭代列表

[英]Jquery to iterate through a list

Following jQuery is not working on given select box. 以下jQuery不适用于给定的选择框。

I want to iterate through all the options of select box. 我想迭代选择框的所有选项。

Where am I going wrong? 我哪里错了?

Am not getting alert("hi") , IE $("#FileType").find('x:option').each(function(){ is not executing. 我没有得到alert("hi") ,IE $("#FileType").find('x:option').each(function(){没有执行。

<x:select id="FileType" width="210px">
        <x:option value="JPG">JPG</x:option>
        <x:option value="PNG">PNG</x:option>
        <x:option value="PDF">PDF</x:option>
        <x:option value="TIF">TIF</x:option>
        <x:option value="BMP">BMP</x:option>
</x:select>

$("#FileType").find('x:option').each(function(){
    alert("hi");                                
    if($(this).val() == AttachmentExtension)
    $("#FileType").val(AttachmentExtension);
});

You need to escape the : character in the selector. 您需要转义选择器中的:字符。

$("#FileType").find('x\\:option').each(function(){
// Your logic. 
});

Here is jsFiddle. 这是jsFiddle。 http://jsfiddle.net/bVz6F/ http://jsfiddle.net/bVz6F/

I am not really sure what technology namespaces your select / option tags but the end result HTML does not have the namespaces. 我不确定您的select / option标签的技术命名空间,但最终结果HTML没有命名空间。 Change to: 改成:

$("#FileType").find('option').each(function(){
    alert("hi");                                
    if($(this).val() == AttachmentExtension)
    $("#FileType").val(AttachmentExtension);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM