我有div的视图,我需要显示日期
我写了这个JavaScript代码
$(document).ready(function() {
var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
newdate = year + "/" + month + "/" + day;
$("#id").append(newdate);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="date" style="width: 100%; height: 10%; background:#1d69b4 ">
</div>
&#13;
答案 0 :(得分:1)
更改
$("#id").append(newdate);
要
$("#date").append(newdate);
这是一个选择器,用于获取ID为日期
的元素答案 1 :(得分:1)
你指的是错误的id。应该是public class RMIInjectionExtension implements Extension
{
private Set< Class< ? > > interfaces = Sets.newHashSet();
void processInjectionPoint( @Observes final ProcessInjectionPoint< ?, ? > aProcessInjectionPoint )
{
// collecting all relevant interfaces
if( aProcessInjectionPoint.getInjectionPoint().getQualifiers().stream()
.anyMatch( RMI.class::isInstance ) )
{
interfaces.add( (Class< ? >)aProcessInjectionPoint.getInjectionPoint().getType() );
}
}
void afterBeanDiscovery( @Observes final AfterBeanDiscovery aAfterBeanDiscovery,
BeanManager aBeanManager )
{
// create beans for the interfaces
// using DeltaSpike BeanBuilder
interfaces.stream().map( a -> new BeanBuilder< Object >( aBeanManager ).beanClass( a )
.qualifiers( (RMI)() -> RMI.class ).beanLifecycle( new RMILifecyle() ).create() )
.forEach( aAfterBeanDiscovery::addBean );
}
}
:
#date
$("#date").append(newdate);
&#13;
$(document).ready(function() {
var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
newdate = year + "/" + month + "/" + day;
$("#date").append(newdate);
});
&#13;
答案 2 :(得分:0)
您使用了错误的选择器 改变
$("#id").append(newdate);
到
$("#date").append(newdate);
答案 3 :(得分:0)
在您的HTML中,您有div id='date'
并将格式化的日期字符串显示在该div中,那么您应该使用.text() or .html()
代替.append()
所以你的脚本应该是
$("#date").text(newdate);
// or
$("#date").html(newdate);