I have created my table dynamically and in one of my td's I have function where I'm passing two different parameters. One of them is ID and does not need quotes around but second parameter need single quotes and I tried so many combinations like "e; or \\' and I could not get what I need. Here is my code:
tbl +="<td><a onClick='DeleteRes(slotsPtc,"+jsData[key].res_ID+")'></a></td>
Code above gave me this:
<a onclick="DeleteRes(slotsPtc,327)"></a>
I'm missing single quotes around first parameter slotsPtc
if anyone can help how I can put single quotes around that parameter please let me know. Thanks.
You can insert quotes in a string by escaping them with a \\
character. I recommend using escaped double quotes for your onclick attribute value and then you can use single quotes without escaping:
tbl +="<td><a onClick=\"DeleteRes('slotsPtc',"+jsData[key].res_ID+")\"></a></td>
You can use '
(or '
) as a single quote in HTML:
tbl += "<td><a onClick='DeleteRes('slotsPtc',"+jsData[key].res_ID+")'></a></td>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.