【发布时间】:2013-08-18 02:57:26
【问题描述】:
我目前正在使用以下代码:
jQuery('#book-a-service').click(function(){
var selectedServices = jQuery('.selected').parent().parent().html();
console.log(selectedServices);
});
然后返回:
<td rowspan="3">Brakes</td>
<td class="service-title">BRAKES SET</td>
<td class="service-description"><p>Setting of front and rear brakes for proper functioning (excluding bleeding)</p></td>
<td class="service-price">R <span id="price-brakes-set">R75</span><div id="select-brakes-set" class="select-service selected"></div>
</td>
这就是我想要的,除了我需要 JSON 中带有“.selected”类的所有元素的数组。 td 标签和“服务价格”只有数值,然后我将如何将这些值插入到 json 对象中?
非常感谢任何帮助..
【问题讨论】:
-
"elements" 是 XML 节点,不能转换为 JSON。您到底想要什么,将一些文本内容作为字符串数组获取?请发布预期结果。
-
这里是a jsFiddle,带有此代码以及正常运行所需的周围标签。
标签: javascript jquery json