سؤال

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.

هل كانت مفيدة؟

المحلول

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">'

نصائح أخرى

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\">'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top