2013-12-09 45 views
1

我有一个自定义标签。我想使用jquery为该自定义标签设置值。 虽然这看起来很愚蠢,但我花了更多时间搜索结果。使用jquery获取自定义标签(包含冒号)值

我的标签是

<error:description code="12345" type="error" result="description" />${description} 

现在我想拿到代码,并通过使用jQuery的值。

请帮助我如何做到这一点。

我没有things i tried area,因为我甚至不知道如何开始。

在此先感谢

回答

7

你需要逃避使用两个回斜线结肠,所以只是做

$('error\\:description').attr("result"); //to get result attribute 
$('error\\:description').text(); //to get the related text 
+0

其给予undefined $('error \\:description')。attr(“result”); –

+0

@MonickaAkilan它的工作原理,请参阅http://jsfiddle.net/fY55k/ –

3

我想这应该这样做:

jQuery("error\\:description").text("your text"); 
+0

它不工作 –

+0

我尝试了它,它对我来说工作得很好。 'jQuery(“error \\:description”)'发现''元素。 – PKeidel