在
如何将 selected="selected"
位添加到来自发送的 $_POST
数据的 HTML
How can i add the selected="selected"
bit to the option in an HTML <select>
input from the sent $_POST
data without an if statement within each option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从编程上来说,你可以这样做:
必须承认我目前没有开发盒来测试上面的代码,但应该没问题。 (如果没有,抱歉。):-)
Programatically, you could do it like this:
Must confess I don't have a dev box up at the moment to test the above code, but it should be OK. (Apologies if not.) :-)
我认为对每个选项使用 if 语句是最有效的。
但是您可以创建一个包含除要选择的选项位置之外的空字符串的数组,以消除 if 语句。
I suppose using an if statement for each option is most efficient.
But you can create an array containing empty strings except for the location of the option you want to select in order to eliminate the if statement.