【发布时间】:2016-06-25 04:06:07
【问题描述】:
我想知道是否有任何 c# 库可以轻松格式化字符串以用于 onclick html 属性属性。
我正在使用 c# 动态生成一个 html 页面,并为一些 onclick 事件动态生成 javascript。我想确保诸如 &"\ ... 等字符不会导致 html 中断或被忽略。例如在下面的示例中,我想显示警报消息 h\m,我不会能够这样做,除非我创建了单独的逻辑来处理 \ 和 &:
function method1(inputValue){
alert(inputValue);
}
<input type="button" value="button1" onclick="method1('h\&#3m')"/>
【问题讨论】:
标签: c# html string-formatting