我该如何写得更短? [英] How can I write it shorter?

查看:65
本文介绍了我该如何写得更短?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<select name="tag">
				<option>Tag:</option>
				<option>1</option>
				<option>2</option>
				<option>3</option>
				<option>4</option>
				<option>5</option>
				<option>6</option>
				<option>7</option>
				<option>8</option>
				<option>9</option>
				<option>10</option>
				<option>11</option>
				<option>12</option>
				<option>13</option>
				<option>14</option>
				<option>15</option>
				<option>16</option>
				<option>17</option>
				<option>18</option>
				<option>19</option>
				<option>20</option>
				<option>21</option>
				<option>22</option>
				<option>23</option>
				<option>24</option>
				<option>25</option>
				<option>26</option>
				<option>27</option>
				<option>28</option>
				<option>29</option>
				<option>30</option>
				<option>31</option>
			</select>


如何缩短时间?编写所有内容的成本太高.并且您可以选择例如2月30日,这是不可能的.


How can I make it shorter? It´s too costly to write it all. And you can choose for example 30th February and that´s impossible.

推荐答案

这将用给定年份(天)中的给定月份填充组合框. />
This will fill the combo box with the given month in a given year, days.

<HTML>
	<HEAD>
		<SCRIPT language="javascript">
		    function add(dumpMonth, dumpYear) {
		        var combo = document.getElementById("combo");
		        days = 32 - new Date(dumpYear, dumpMonth - 1, 32).getDate();

                for(i=1; i<=days; i++)
		         {
		            option = document.createElement("option");
		            option.text = i;
		            option.value = i;
		            try {
		                combo.add(option, null); 
		            } catch (error) {
		                combo.add(option);
		            }
		        }
		    }
</SCRIPT>
</HEAD>
    <BODY onload="add(2,2011)">
        Select Day: <select name="combo" id="combo"></select>
    </BODY>
</HTML>



希望对您有所帮助.



Hope it helps.


我看不出为什么它太贵了,CTRL V按钮是可重复使用的. 但是,正如其他人指出的那样,日期函数是可用的,应该使用.



或者您可以通过循环数组加载.
只需使用一个月的案例,然后捉弄您的叔叔.
I fail to see why it is too costly, the CTRL V button is re-usable.
However, as others have pointed out, the date function is available and should be used.



Or you could load by a looped array.
Just use a case for the months and bobs your uncle.


使用JavaScript创建select和option元素.使用日期 [
Use JavaScript to create the select and option elements. Use the Date[^] object and create a loop.


这篇关于我该如何写得更短?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆