gpt4 book ai didi

javascript - parse Int 不适用于日期函数

转载 作者:行者123 更新时间:2023-12-03 07:14:59 24 4
gpt4 key购买 nike

我正在使用硬编码日期值在 select 中开发简单的 html 控件,从这个值我将它分成两部分,从返回的值我想将日期和月份视为警报消息,但它向我显示为警报中的 NaNNaN 消息而不是返回我的格式化消息。

<p>Click the button to display todays day of the month.</p>
<select id="account_type" name="account_type">

<option value="1">Thursday May 29 at 2:00 PM ET</option>
<option value="2">Tuesday May 22 at 10:00 AM ET</option>
<option value="2">Friday May 22 at 10:00 AM ET</option>
<option value="2">Monday May 22 at 10:00 AM ET</option>
<option value="2">Wednesday May 22 at 10:00 AM ET</option>
<option value="2">Saturday May 22 at 10:00 AM ET</option>

</select>
<input type="image" id="submit" alt="Submit">
$(document).ready(function() {
$("#submit").click(function() {
var str = $('#account_type option:selected').text();
var spl = str.split("at");
// alert("str : " + spl[0]);
var d = new Date(spl[0]);
var d1 = d.getDay();
var d11 = parseInt(d1);
var d2 = d.getMonth();
var d12 = parseInt(d2);
var d3 = d.getDate();
var d13 = parseInt(d3);
var fulldate = d11 + "" + d12;
alert("Detail is : " + fulldate);
});
});

最佳答案

您也在星期六(at)urday使用“at”这个关键字分割文本使用其他字符或单词来拆分。我只是修改你的代码试试!

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#submit").click(function() {
var str = $('#account_type option:selected').text();
var spl = str.split(",");
// alert("str : "+spl[0]);
var d = new Date(spl[0]);
var d1 = d.getDay();
var d11 = parseInt(d1);
var d2 = d.getMonth();
var d12 = parseInt(d2);
var d3 = d.getDate();
var d13 = parseInt(d3);
var fulldate = d11 + " " + d12;
alert("Detail is : " + fulldate);
});
});
</script>
</head>

<body>
<p>Click the button to display todays day of the month.</p>
<select id="account_type" name="account_type">
<option value="1">Thursday May 29 , 2:00 PM ET</option>
<option value="2">Tuesday May 22 , 10:00 AM ET</option>
<option value="2">Friday May 22 , 10:00 AM ET</option>
<option value="2">Monday May 22 , 10:00 AM ET</option>
<option value="2">Wednesday May 22 , 10:00 AM ET</option>
<option value="2">Saturday May 22 , 10:00 AM ET</option>
</select>
<input type="image" id="submit" alt="Submit">
</body>
</html>

关于javascript - parse Int 不适用于日期函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36468331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com