我如何合并这两个javascript代码

How do I merge these two javascript codes?

本文关键字:两个 javascript 代码 合并 何合并      更新时间:2023-09-26

我想添加以下代码:

<script type="text/javascript" src="http://www.formstack.com/forms/js.php?1134414-uqmj2UXxEw-v2">
</script>
<noscript>
<a href="http://www.formstack.com/forms/CampusEnterprises-chopped_greens_order_form__copy" title="Online Form">
Online Form - Chopped Greens Order Form - COPY
</a>
</noscript>

在以下javascript代码末尾的isOpen()方法调用中:

<head>
<script type="text/javascript">
var theDate = new Date();
var dayOfWeek = theDate.getUTCDay();
// Returns true if the restaurant is open
function isOpen()
{
    //I'll fill this in later, for now, return true
    return true;
}
</script>
</head><body>
<script type = "text/javascript">
if(isOpen())
{
    //ADD CODE HERE
}
</script>
</body>

然而,当我试图只是复制和粘贴两个在一起它不工作。我认为这与嵌套标签有关但我不确定

您可以动态地将脚本写入文档。

<body>
<script type = "text/javascript">
if(isOpen())
{
    document.write('<script type="text/javascript" src="http://www.formstack.com/forms/js.php?1134414-uqmj2UXxEw-v2"></script>');
}
</script>
<noscript>
<a href="http://www.formstack.com/forms/CampusEnterprises-chopped_greens_order_form__copy" title="Online Form">
Online Form - Chopped Greens Order Form - COPY
</a>
</noscript>
</body>

正如@Jared Farrish在评论中指出的那样,您不妨直接在页面上使用noscript标记。