手动设置html/css时间时间
问题描述:
我是jquery和javascript的新手。 我已经创建了css旋转时钟,如http://css-tricks.com/css3-clock/中所述。 正常情况下,此时钟使用JScript Date()。getSecond()方法获取本地机器时间。有没有什么办法可以使用javascript或jquery手动设置时间/分钟下拉菜单。 这里是旋转钟表的代码。手动设置html/css时间时间
<script type="text/javascript">
$(document).ready(function() {
setInterval(function() {
var seconds = new Date().getSeconds();
var sdegree = seconds * 6;
var srotate = "rotate(" + sdegree + "deg)";
$("#sec").css({"-moz-transform" : srotate, "-webkit-transform" : srotate});
}, 1000);
setInterval(function() {
var hours = new Date().getHours();
var mins = new Date().getMinutes();
var hdegree = hours * 30 + (mins/2);
var hrotate = "rotate(" + hdegree + "deg)";
$("#hour").css({"-moz-transform" : hrotate, "-webkit-transform" : hrotate});
}, 1000);
setInterval(function() {
var mins = new Date().getMinutes();
var mdegree = mins * 6;
var mrotate = "rotate(" + mdegree + "deg)";
$("#min").css({"-moz-transform" : mrotate, "-webkit-transform" : mrotate});
}, 1000);
});
</script>
我想使用下拉式更改小时/分钟变量。请帮忙。
答
function setTime(hours, minutes, seconds) {
$("#hour").css({"-moz-transform" : "rotate(" + (hours * 30 + (minutess/2)) + "deg)", "-webkit-transform" : "rotate(" + (hours * 30 + (minutes/2)) + "deg)"});
$("#min").css({"-moz-transform" : "rotate(" + (minutes * 6) + "deg)", "-webkit-transform" : "rotate(" + (minutes * 6) + "deg)"});
$("#sec").css({"-moz-transform" : "rotate(" + (seconds * 6) + "deg)", "-webkit-transform" : "rotate(" + (seconds * 6) + "deg)"});
}
应该工作,但没有测试它。自己实现这个下拉菜单。
感谢您的回答。您的解决方案看起来很简单,但我不知道如何从下拉菜单中获取“小时”,“分钟”值。 – AzAh 2013-04-23 18:04:15
使用jQuery ['.val()'](http://api.jquery.com/val/)方法。 – ghost 2013-04-23 18:37:27