填充“月份”下拉式菜单 [英] Populating "Month" Dropdown Menu
问题描述
我可以通过插入
value ="< ;?来获取当前月份以显示在文本框中print strftime("%B"); ?>">进入表格中的特定文本框的代码,但是我如何用所有月份的
名称填充下拉列表,当前的名称为默认 '因为它
将在文本框示例中? TIA
I can get the current month to display in a text box by inserting
value="<? print strftime("%B"); ?>"> into the code for that
particular text box on a form but how can I populate a drop down with
names of all the months with the current one being ''default'' as it
would be in the text box example? TIA
推荐答案
封面写道:
我可以通过插入
value ="<? print strftime("%B"); ?>">在表单上的特定文本框的代码中,但是我如何用所有月份的名称填充下拉列表,其中当前的名称为默认,因为它将是
在文本框示例中? TIA
I can get the current month to display in a text box by inserting
value="<? print strftime("%B"); ?>"> into the code for that
particular text box on a form but how can I populate a drop down with
names of all the months with the current one being ''default'' as it
would be in the text box example? TIA
您需要以下内容:
< select name =" month">
< option<?php if(date(" m")==" 01")echo" selected" ?> value =" 01"> Jan< / option>
< option<?php if(date(" m")==" 02" )回声选择 ?> value =" 02"> 2月< / option>
...依此类推......
< ; / select>
如果你考虑的话,使用for循环的其他更简洁的方法。
You want the following:
<select name="month">
<option <?php if (date("m")=="01") echo "selected" ?>value="01">Jan</option>
<option <?php if (date("m")=="02") echo "selected" ?>value="02">Feb</option>
... and so on...
</select>
Other tidier ways to do it using for loops too if you think about it.
cover写道:
我可以通过插入
value ="< ;?来获取当前月份以显示在文本框中print strftime("%B"); ?>">在表单上的特定文本框的代码中,但是我如何用所有月份的名称填充下拉列表,其中当前的名称为默认,因为它将是
在文本框示例中? TIA
I can get the current month to display in a text box by inserting
value="<? print strftime("%B"); ?>"> into the code for that
particular text box on a form but how can I populate a drop down with
names of all the months with the current one being ''default'' as it
would be in the text box example? TIA
/ **
*生成一个月的HTML选择元素
*
* @param string
/**
* generates an HTML select element for the month
*
* @param string
name HTML字段的名称
* @param int
name The name of the HTML field
* @param int
这篇关于填充“月份”下拉式菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!