如何合并这两个javascript代码?

时间:2023-01-19 09:17:42

I would like to add this code:

我想添加此代码:

<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>

into the call of the isOpen() method at the end of the following javascript code:

在以下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>

However, when I try to just copy and paste the two together it doesn't work. I think it has something to do with nested tags but I'm not sure

但是,当我尝试将两者复制并粘贴在一起时,它不起作用。我认为这与嵌套标签有关,但我不确定

1 个解决方案

#1


3  

You can write out the script into the document dynamically.

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

<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>

As @Jared Farrish noted in the comments, you might as well use the noscript tag directly on the page.

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

#1


3  

You can write out the script into the document dynamically.

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

<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>

As @Jared Farrish noted in the comments, you might as well use the noscript tag directly on the page.

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