Too*_*ool 0 javascript string jquery
无论我尝试什么,Jquery似乎都无法将str2的类型转换为字符串.
function parseXml(xml)
{
$(xml).find("product").each(function()
{
var str1 = "div.timer";
var **str2** = $(this).find("id");
$("div.timer17").html(str1 + str2);
});
}
Run Code Online (Sandbox Code Playgroud)
每次运行此函数时,div.timer17的内容都会更改为div.timer [object Object].
我尝试将对象Object转换为带有新String(obj)的字符串,使用json.stringify等.没有任何效果.请帮忙.
我的目标是将str2附加到str1,所以我可以得到想要的选择器(例如,div.timer25).
这是xml:
<?xml version="1.0" encoding="utf-8" ?>
<products>
<product cookie="The red">
<timediff>02:28:59</timediff>
<username>denis</username>
<price>25</price>
<id>17</id>
</product>
<product cookie="The red">
<timediff>00:28:59</timediff>
<username>denis</username>
<price>35</price>
<id>18</id>
</product>
</products>
Run Code Online (Sandbox Code Playgroud)
假设你想要text或html我认为你想要这个
var str2 = $(this).find("id").text();
Run Code Online (Sandbox Code Playgroud)
要么
var str2 = $(this).find("id").html();
Run Code Online (Sandbox Code Playgroud)