![](/img/trans.png)
[英]how can I pass a function into another function in JavaScript
[英]How can I pass xml to another function?
我需要var命令才能给我xml,并且在onclick函数中我想将此xml传递给matte_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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.