2009-08-28 21 views
0

我有一个包含在表单中的日期的输入形式:上午12点00分59秒,2010更改的形式输入到当前时间[jquery的]

最有可能的时间12月25日我会想要将此更改为当前时间。

是否有可能有一个按钮或链接旁边的输入框,单击时的jquery会更新时间为当前时间。

(我已经使用jquery别的东西所以想那会更容易更多的代码添加到不是从头码我的js文件)

我不能做到这一点。这里的HTML:

<form> 
    ... 
    <p>Time: <input name="time" id="time" type="text" size="30" value="<?php echo $date; ?>"><a href="" name="time-update">Update to now</a></p> 
    ... 
</form> 

而且继承人的JS:

$("a[time-update]").click(function(event) { 
    var time = Date(); 
    $("#time").value = time; 
    event.preventDefault(); 
}); 

它只是重新加载页面。

回答

0

因为它可能抛出一个异常,试试这个:

$(document).ready(function(){ 

    $("a[time-update]").click(function(event) { 

    var time = new Date(); 
    $("#time").val(time); 
    event.preventDefault(); 

    }); 

}); 

希望它能帮助,思南。