【问题标题】:Issue with the single quote with passing a string to the javascript function将字符串传递给javascript函数时出现单引号问题
【发布时间】:2014-01-31 19:18:05
【问题描述】:

我正在使用自定义标签从模板中获取字段的标题。在本例中,有一个字段“customerEmailTitle”,其中包含字符串“Riot Team's Email”。我在 javascript 函数 checkEmailAddress 中传递它(如下所示):

<input onBlur="checkEmailAddress(this, 'The input is an invalid <getName:getField fieldKey="customerEmailTitle"/> address')" />

但 Riot Team 电子邮件中的单引号似乎使页面无法正常处理,并且无法正确处理 javascript。我尝试转义输入标签中的单引号和双引号,但似乎没有任何效果。有人对如何处理这个问题有更好的想法吗?

【问题讨论】:

    标签: javascript jsp


    【解决方案1】:

    它可能对你有帮助。因为您可以在输入元素的数据属性上设置数据/字符串。

    <html>
    <body>
    <input data-message="'The input is an invalid <getName:getField fieldKey='customerEmailTitle'/> address')" onblur="checkEmailAddress(this)" type="text" />
    
    </body>
    
    <script>
        function checkEmailAddress(elm){
            alert(elm.dataset['message']);
        }
    </script>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 2011-04-14
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      相关资源
      最近更新 更多