从 JavaScript 中的 XAML 元素中删除属性

Removing attribute from a XAML element in JavaScript

本文关键字:删除 属性 元素 XAML JavaScript 中的      更新时间:2023-09-26

我正在 Silverlight Web 应用程序中处理 XAML 文件。我正在使用JavaScript来操作xaml文件并响应事件。我在图表上有一个椭圆元素列表,当我单击其中一个时,椭圆的填充设置为另一种颜色,覆盖样式中的填充集。

因此,在单击椭圆后,我实际上最终会得到这样的结果:

<Ellipse x:Name="g46" Style="{StaticResource GainValue}" Canvas.Top="136" Canvas.Left="766" MouseLeftButtonUp="onDotClicked" Fill="Red" />

现在,当我单击第二个椭圆时,我想重置单击的第一个椭圆的颜色。不幸的是,我不知道如何使用Javascript删除属于Ellipse(或任何其他)元素的属性。将属性设置为 null 会给椭圆分配一个空字符串,我已经在 dot.removeAttribute('Fill')dot['Fill'].remove 上经历了六种变体,但没有成功。

我基本上不知道应该用来在JavaScript中操作xaml对象的语法。我找到了一些描述 DOM 语法等的参考页面,但没有与我在这里实际使用的语法相对应的内容。

最好的办法可能是使用 jQuery 将 XAML 加载为 XML。

你可以做

var xamlDocument = getYourXaml(); // Implement this or replace with however you're getting the XAML
var xml = $(xamlDocument);
xml.removeAttr('Fill');
//If you need to save your XAML do it here, if it's part of the page it should just work.

更多信息: http://api.jquery.com/jQuery.parseXML/