[英]Jquery to change value of “value” attribute in xml element
Example (snippet) : 示例(摘要):
<FIELD name="xxxxxxxx" refname="xxxx" type="String" reportable="dimension">
<WHEN field="xxxxxxxx" value="xxxxxxxxxxxxxxxxx">
<ALLOWEXISTINGVALUE />
<ALLOWEDVALUES expanditems="true">
<LISTITEM value="n.a." />
<LISTITEM value="Test" />
</ALLOWEDVALUES>
</WHEN>
<WHEN field="yyyyyyyyyyyyy" value="yyyyyyy">
<ALLOWEXISTINGVALUE />
<ALLOWEDVALUES expanditems="true">
<LISTITEM value="n.a." />
</ALLOWEDVALUES>
</WHEN>
</FIELD>
When I do: 当我做:
var $listItem = $(xmlDoc).find("FIELD[name='" + dependentFieldType + "'] > WHEN[value='" + productName + "'] ALLOWEDVALUES > LISTITEM[value='" + listItem + "']");
$listItem.val(newListItemValue);
It does not update the listitem value 它不会更新listitem值
Also tried .prop("value") and .attr("value") on $listItem. 还尝试对$ listItem使用.prop(“ value”)和.attr(“ value”)。
Would be very thankful for a working jsfiddle with the above xml sample, which edits the value attribute of LISTITEM 非常感谢使用上面的xml示例的jsfiddle,该示例可以编辑LISTITEM的value属性
Every time you call $(xml)
you are creating a new DOM object based on the original string. 每次调用$(xml)
都会基于原始字符串创建一个新的DOM对象。 Try this instead: 尝试以下方法:
j = $(xml);
j.find('attr').attr('foo', 'bar');
console.log(j.html());
Now you parse the XML string only once and update the resulting node. 现在,您只解析XML字符串一次,并更新结果节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.