简体   繁体   中英

How to add checkbox in html table?

I need to add a checkbox in a html table I know the usual method like

    <td>  
        <input type="checkbox" name ="chk1" />  
    </td>

My current code is

string html=""; 
html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + </th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + </td></td>+"<input type="checkbox" name ="chk1" /> "  +</td>  </tr>"; 
html += "</table>";

but this gives an error

You have missed some quotes

please use this code

string html=""; 
html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + "</th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + "</td></td>"+"<input type='checkbox' name ='chk1' /> "  +"</td>  </tr>"; 
html += "</table>";

It appears that you're missing a quote, also you can get rid of some of the quotes (and rows):

string html=""; 
html += "<table>";
html += "<tr><th>A</th><th>B</th><th>C</th></tr>";
html += "<tr><td>0</td><td>1</td><td>2</td></td><input type=\"checkbox\" name =\"chk1\" /></td></tr>"; 
html += "</table>";

No need of concatenations, just put single quotes outside as given in the example below:

string html = ''; 
html += '<table>';
html += '<tr><th>A</th><th>A</th><th>C</th></tr>';
html += '<tr><td>0</td><td>1</td><td>2</td></td><input type="checkbox" name ="chk1"  /></td></tr>'; 
html += '</table>';

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM