如何将xml传递给另一个函数

How can I pass xml to another function?

本文关键字:另一个 函数 xml      更新时间:2024-06-05

我需要var order来给我xml,在onclick函数中,我想把这个xml传递给matt_design_change()。现在,当我这样做的时候,当我调用console.log时,输出的是什么,它只给了我"[object object]",而没有其他内容。

我有以下代码:

function matte_design_change_design_type(element)
{
  var selected_type = element.options[element.selectedIndex].value;
  $(document).ready(function()
  {
    $.ajax({
      type: "GET",
      url: SITE_URL + "/system/components/xml/" + selected_type,
      dataType: 'xml',
      success: function(xml) {
        var output = [];
        $('component', xml).each(function(i, el) {
            var thumb = $("thumb", this).text();
            var cid = $("cid", this).text().replace("[DEFAULT_MATTE_CID]", "");
            var order = $("Order", this); //I want this to be xml
            output.push('<img id="cid_' + cid + '" src="' + SITE_URL + '/system/components/compimg/' + thumb + '/flashthumb" alt="' + cid + '" onclick="matte_design_change(''' + cid + ''', ''' + thumb + ''', ''' + order + ''');" />'); // I want to pass order as xml to matte_design_change
            $('#matte_designs_strip_wrapper').html(output.join(''));
        });
      }
    });
  });
}
function matte_design_change(cid, thumb, order)
{
  $( "#frame_window" ).empty();
  var imageObj = new Image();
  imageObj.onload = (function()
  {
    document.getElementById("frame_window").appendChild(imageObj);
  });
  imageObj.id = "matte_" + cid;
  imageObj.src = SITE_URL + '/system/components/compimg/' + thumb + '/full_thumb';
  console.log(order);
}

您应该能够轻松地将XML转换为字符串,然后将其作为参数传递。周围有许多例子;这个可能有用:

http://jonahacquah.blogspot.it/2012/03/convert-xmldocument-to-xml-string-in.html