问问题
163 次
1 回答
0
您可以重写代码以使其更优雅:
var dateformat = document.getElementById("dateformat"),
options = [{
text: month + "/" + day + "/" + fullyear,
value: "M/d/yyyy"
}, {
text: monthwz + "/" + daywz + "/" + fullyear,
value: "MM/dd/yyyy"
}, {
text: day + "/" + month + "/" + fullyear,
value: "d/M/yyyy"
}];
for (var i = 0, len = options.length; i < len; i++) {
var option = options[i],
element = new Option(option.text, option.value);
dateformat.options[dateformat.options.length] = element;
}
// one way to set the selected value:
dateformat.value = <?php print json_encode($value); ?>;
演示:http: //jsfiddle.net/vPerj/
于 2013-03-27T16:44:53.577 回答