Pregunta

i am trying to assign the following to a string to append.

<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">

but when i try:

var str = "<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">"

I get a syntax error. How do I solve the problem of the double quotation inside a string? i actually do need it because of how jsp taglibs work.

¿Fue útil?

Solución

You have a quote issue. The double quotes for your string are colliding with the double quotes in your attributes in your string.

var str = "<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">"

should be

var str = '<table id="<%=tableName%>" width="70%" cellpadding="0" cellspacing="0" border="0">'

Otros consejos

You either need to escape the double quotes in your string (as you are using double quoted strings)

var str = "<table id=\"<%=tableName%>\" width=\"70%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"

OR

user a single quoted string

var str = '<table id=\"<%=tableName%>\" width=\"70%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">'
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top