使用 javascript rrule.min.js 实施 RRule

Implement RRule using javascript rrule.min.js

我正在尝试将库 https://github.com/jakubroztocil/rrule 添加到我的网页中。

但我收到错误:Uncaught SyntaxError: Unexpected token {

我试过

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://jakubroztocil.github.io/rrule/dist/es5/rrule-tz.min.js"></script>

<script>
$(document).ready(function(){

import { RRule, RRuleSet, rrulestr } from 'rrule'
alert(rrulestr('DTSTART:20120201T023000Z\nRRULE:FREQ=MONTHLY;COUNT=5')
)

});
</script>
</head>
<body>



</body>
</html>

工作代码

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://jakubroztocil.github.io/rrule/dist/es5/rrule-tz.min.js"></script>

<script>
$(document).ready(function(){

alert(rrule.rrulestr('DTSTART:20120201T023000Z\nRRULE:FREQ=MONTHLY;COUNT=5'));

});
</script>
</head>
<body>



</body>
</html>

导入在脚本标签内不起作用,请使用以下解决方案,其中插入规则缩小的 js 并使用函数。

<!DOCTYPE html>
<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script src="https://jakubroztocil.github.io/rrule/dist/es5/rrule-tz.min.js"></script>

    <script>
        $(document).ready(function () {
            const RRule = rrule.RRule;

            const rule = new RRule({
                freq: RRule.WEEKLY,
                interval: 5,
                byweekday: [RRule.MO, RRule.FR],
                dtstart: new Date(Date.UTC(2015, 1, 1, 10, 30)),
                until: new Date(Date.UTC(2020, 12, 31))
            });

            alert(rule.between(new Date(Date.UTC(2018, 7, 1)), new Date(Date.UTC(2019, 8, 1))));
        });
    </script>
</head>

<body>

</body>

</html>