【问题标题】:How can I escape this HTML string within Java?如何在 Java 中转义这个 HTML 字符串?
【发布时间】:2014-10-07 16:19:54
【问题描述】:

我在将 buttonClassvariable 添加到类属性时遇到问题。如何在这里转义双引号和单引号?

 String buttonClass= changed ? "changeButton" : "dontChangeButton";
 button.append("<input id='" + id + "' type='button' value='" + buttonValue + "' class='" + buttonClass
 + "' ui-button ui-widget' />");

【问题讨论】:

    标签: java html escaping quotes html-escape-characters


    【解决方案1】:

    您可以使用反斜杠转义字符,或将字符串发布到本网站并让它为您工作:http://www.freeformatter.com/java-dotnet-escape.html

    【讨论】:

      【解决方案2】:

      通过使用反斜杠“转义”运算符,即:“\”Hello Quotes\“”;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-16
        • 2010-11-16
        • 2011-04-02
        • 1970-01-01
        • 2012-05-27
        • 2021-08-24
        相关资源
        最近更新 更多