[英]Escaping quotes inside quotes in html
Not sure why this error is happening in Chrome and Edge, but not in IE (yeah business team is still stuck with it)不知道为什么这个错误发生在 Chrome 和 Edge 中,但不是在 IE 中(是的,业务团队仍然坚持它)
Seeing "Uncaught SyntaxError: Unexpected end of input" on this html line在此 html 行上看到“Uncaught SyntaxError: Unexpected end of input”
<TR onmouseover="rowColor(this, true);" onmouseout="rowColor(this, false);" onclick='workTicket('displayTicket.action?TICKETID=1367698&TTID=14','1367698');'>
and the following is the corresponding jsp/struts line以下是对应的jsp/struts行
<TR onmouseover="rowColor(this, true);" onmouseout="rowColor(this, false);" onclick='workTicket(<c:out value="'displayTicket.action?TICKETID=${dispTO.ticketNbr}&TTID=${dispTO.ticketTypeId}','${dispTO.ticketNbr}'" />);'>
I don't see anything wrong in the above line except the onclick attribute starts with single quote.除了 onclick 属性以单引号开头之外,我在上面的行中没有看到任何错误。 Any idea why this is happening?
知道为什么会这样吗?
You MUST have a complete set of OTHER quotes inside an attribute您必须在属性中包含一组完整的 OTHER 引号
<TR onmouseover="rowColor(this, true);"
onmouseout="rowColor(this, false);"
onclick="workTicket('displayTicket.action?TICKETID=1367698&TTID=14','1367698');">
There is no problem with the c:out c没有问题:out
<TR onmouseover="rowColor(this, true);"
onmouseout="rowColor(this, false);"
onclick="workTicket(<c:out value="'displayTicket.action?TICKETID=${dispTO.ticketNbr}&TTID=${dispTO.ticketTypeId}','${dispTO.ticketNbr}'" />);">
will work将工作
BUT this is in my opinion better但我认为这更好
data-tickettypeid="<c:out value="${dispTO.ticketTypeId}" />"
data-ticketnbr="<c:out value="${dispTO.ticketNbr}" />"
onclick="workTicket(`displayTicket.action?TICKETID=${this.dataset.tickettypeid}&TTID=${this.dataset.ticketnbr}`,this.dataset.tickettypeid)"
and even better:甚至更好:
document.getElementById("myTable").addEventListener("click",function(e) {
const tgt = e.target.closest("tr");
if (tgt && tgt.getAttribute("data-tickettypeid")) {
workTicket(`displayTicket.action?TICKETID=${tgt.dataset.tickettypeid}&TTID=${tgt.dataset.ticketnbr}`,tgt.dataset.tickettypeid)
}
})
then you can use那么你可以使用
<tr data-tickettypeid="<c:out value="${dispTO.ticketTypeId}" />"
data-ticketnbr="<c:out value="${dispTO.ticketNbr}" />">
As for the mouseover and out, use CSS至于鼠标悬停和移出,使用 CSS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.