本文介绍了是否基于Iframe的日期和时间的动态网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个动态iframe,该页面以yyyy-mm-dd格式加载以该日期命名的页面,并在末尾添加+ AM和+ PM.示例: https://example.com/display/stuff/2016-10-02+ AM

I'm trying to create a dynamic iframe that loads a page that is named after the date in yyyy-mm-dd format with the addition of +AM and +PM added at the end.Example: https://example.com/display/stuff/2016-10-02+AM

这是我到目前为止所拥有的..我没有收到任何语法错误,但不会呈现.

This is what I have so far.. I'm not getting any syntax errors but it won't render.

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
    var today = new Date();
    var dd = today.getDate;
    var mm = today.getMonth;
    var yyyy = today.getFullYear;
    var h = h > 12 ? h - 12 + 'PM' : h + 'AM';
    if (dd < 10) {
        dd = '0' + dd;
    }
    if (mm < 10) {
        mm = '0' + mm;
    }
    var today = yyyy + '-' + mm + '-' + dd + '+' + h;
</script>
document.body.innerHTML = ('<iframe src="https://example.com/display/stuff/\'today'/"'</iframe>')
</body>
</html>

推荐答案

您缺少一些内容.

date.getDate

这是一个函数,应该这样称呼

This is a function so should be called like

date.getDate()

您还可以在< script> 标记之外调用您的javascript代码,该代码不会被评估.

Also your calling your javascript code outside of the <script> tag which won't be evaluated.

这是半工作代码:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth();
    var yyyy = today.getFullYear();
    var h = h > 12 ? h - 12 + 'PM' : h + 'AM';
    if (dd < 10) {
        dd = '0' + dd;
    }
    if (mm < 10) {
        mm = '0' + mm;
    }
    var today = yyyy + '-' + mm + '-' + dd + '+' + h;
    document.body.innerHTML = '<iframe src="https://example.com/display/stuff/'+ today+'"></iframe>';
</script>
</body>
</html>

这篇关于是否基于Iframe的日期和时间的动态网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 15:17