2013-05-14 40 views
0

我正在使用jquery帖子来返回一个xml数据集。我最初使用下拉式窗体控件来筛选返回的数据。从jquery中的切换图像返回值的数组

现在我希望能够显示制造商图标列表,然后让用户点击这些来切换它们的开启和关闭。

$('#sho').click(function() { 
    $(this).toggleClass('highlight'); 
    if ($(this).hasClass('highlight')){ 
      $(this).attr('alt','sho'); 
      alert(manufac); 
    } else { 
      $(this).attr('alt',''); 
    }}); 

目前我有切换代码,以便图像在点击时只是获得一个框。我也用一个值来设置ALT属性。我希望能够收集所有具有值的alt属性并将它们传递给我的jquery文章。

function loadXML(so) { 
<!-- Clothing Version --> 
timestamp = Math.round(new Date().getTime()/1000); 

$("#wrapper").html('<div id="load"><img src="http://static.phmotorcyclescom.dev/images/loading.gif" alt="loading" align="center" /></div>'); 
$("#results").empty(); 
$.post("http://www.phmotorcycles.current/supportScripts/clothingXML.asp",{ 
    productGroup: "hel", 
    sortOrder: so, 
    qt: "group", 
    ts: timestamp, 
    manufacturer:$("input:checkbox[name='man[]']:checked").map(function() { 
     return $(this).val(); 
    }).get()}, <----- I need to replace this section of code 
    function(xml) { 
     convertXML(xml); 
     $("#wrapper").empty(); 
     $('#results').html("Your Product was not found"); 
    },"xml") 

}

最终获取传递给设备厂变量的值仅仅是一个逗号分隔值如ARA,笑,沙名单,ARA

是否有人对此有什么想法请。我已经尝试使用.each()方法,并设法让它提醒所有正值,但我无法将它们连接成一个字符串。

$('img').each(function(){ 
      var id = $(this).attr("id"); 
      var altVal = $(this).attr("alt"); 
      if (altVal != '') { 
       alert($('img#' + id).attr('alt')); 
      } 
     }); 

一如既往的帮助非常感谢。

干杯 格雷厄姆

回答

1

试试这个..

manufacturer : function() { 
    var ar= new Array(); 
    $("img.highlight").each(function(){ 
    ar.push($(this).attr("alt")); 
    }); 
    return ar.join(","); 
} 

的jsfiddle显示推的用途,并加入

http://jsfiddle.net/jCdpf/

+0

好极了,就像一个魅力。非常感谢 – EvilKermitSaurus 2013-05-14 14:43:05