首页javascriptselectJavascript Form - 如何将选择选项文本转换为日期

Javascript Form - 如何将选择选项文本转换为日期

我们想知道如何将选择选项文本转换为日期。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    $("#monday").click(function(){
        var sel = document.getElementById("monday");
        var text = sel.options[sel.selectedIndex].text;
        var mon=new Date(text);
        console.log(mon);
        document.getElementById("mondaydate").innerHTML = mon.setDate(mon.getDate()+0);
    });
});
</script>
</head>
<body>
  <select id="monday" name="monday">
    <option value="7">Mon 1/7/2013 (Week 02)</option>
    <option value="14">Mon 1/14/2013 (Week 03)</option> // etc...
  </select>
  <div id='mondaydate'>Mon 1/7/2013 (Week 02)</div>
</body>
</html>