【问题标题】:Get a custom tag (containing colon) value using jquery使用 jquery 获取自定义标签(包含冒号)值
【发布时间】:2013-12-09 10:44:16
【问题描述】:

我有一个自定义标签。我想使用 jquery 为该自定义标签设置值。 虽然这看起来是一个愚蠢的问题,但我花了更多时间来搜索结果。

我的标签是

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

现在我想要获取该标签,并且必须使用 jquery 传递值。

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

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

提前致谢

【问题讨论】:

    标签: jquery custom-tag


    【解决方案1】:

    你需要使用两个反斜杠来转义冒号,所以就这样做

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

    【讨论】:

    • 它给出未定义的 $('error\\:description').attr("result");
    【解决方案2】:

    我认为应该这样做:

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

    【讨论】:

    • 我试过了,对我来说效果很好。 jQuery("error\\:description") 找到 &lt;error:description code="12345" type="error" result="description" /&gt; 元素。
    猜你喜欢
    • 1970-01-01
    • 2012-01-14
    • 2011-01-23
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    相关资源
    最近更新 更多