html - 生成 HTML

标签 html c

     <form action=post ...>
     //...
     <td><select name="data">
        <option value="1" $isSelected_1>1</option>
                    //....100 options...
        <option value="148" $isSelected_100>100</option>
         </select>
    </td>
    //...

我在 C 程序中生成 html。但是,我需要检查选择或未选择的选项,我认为创建 100 个变量(还有很多 if 语句......)是不好的。什么可能是最好的解决方案?

最佳答案

一个数组,然后循环? 伪代码:

a[1] = true;
...
a[n] = false;

for(i = 1 -> n)
 <option value='i'+(a[i] ? selected : '')>...

关于html - 生成 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458464/

相关文章:

c - "Debug Assertion Failed"Visual Studio 2015

c - C 中人类可读的十六进制时间戳

javascript - IE 和 html5 视频停止工作

html - 渲染多级html列表的算法

javascript - `data-include` 属性可能如何工作?

html - CodeIgniter CSS 不会链接到 html

html - 我应该使用什么语言/工具来解析 HTML?

c++ - 无法让 Makefile 工作

c - 冒泡排序——输出整数的字符串

在文本文件而非目录上调用 opendir(3)