Javascript 将函数值切换到当前日期而不是精确日期
我将如何修改下面的函数以指定当前日期而不是2013年11月4日的值Javascript 将函数值切换到当前日期而不是精确日期,javascript,jquery,sharepoint,Javascript,Jquery,Sharepoint,我将如何修改下面的函数以指定当前日期而不是2013年11月4日的值 <script type="text/javascript"> $('#FormsPageID table tr:nth-child(12) td:nth-child(2) div span span input') .on('focus', function(){ var $this = $(this); if($this.val() == '4/11/2013'){
<script type="text/javascript">
$('#FormsPageID table tr:nth-child(12) td:nth-child(2) div span span input')
.on('focus', function(){
var $this = $(this);
if($this.val() == '4/11/2013'){
$this.val('');
}
})
.on('blur', function(){
var $this = $(this);
if($this.val() == ''){
$this.val('4/11/2013');
}
});
</script>
$(“#FormsPageID表tr:n子(12)td:n子(2)div span input')
.on('focus',function(){
var$this=$(this);
如果($this.val()=“4/11/2013”){
$this.val(“”);
}
})
.on('blur',function(){
var$this=$(this);
如果($this.val()=''){
$this.val('4/11/2013');
}
});
这会有用的
var date = new Date();
var strDate = (date.getMonth() + 1) + "/" + date.getDate() + "/" +date.getFullYear()
基于Parthik的答案,您可以将其作为一个函数,在.val()中调用它 在代码中,更改:
$this.val('4/11/2013');
到
单击此按钮:只是为了确定,我应该将此函数放在现有代码中的什么位置?在
.on
函数中的if语句中。
$this.val('4/11/2013');
$this.val(getCurrentDate());