如何在html表中添加复选框?

时间:2013-01-23 05:17:37

标签: c# asp.net html

我需要在html表中添加一个复选框,我知道通常的方法,如

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

我目前的代码是

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

但这会产生错误

3 个答案:

答案 0 :(得分:2)

你错过了一些引用

请使用此代码

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

答案 1 :(得分:2)

看起来你错过了一个引用,你也可以删掉一些引号(和行):

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

答案 2 :(得分:1)

不需要连接,只需将单引号放在外面,如下例所示:

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