2011-11-05 86 views
1

我想這個代碼添加:如何合併這兩個javascript代碼?

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

然而,當我試圖把剛纔複製並將它們粘貼在一起不起作用。我認爲它與嵌套標記有關,但我不確定

+0

什麼不行? –

+0

@ SteveO'Connor - 請參閱OP的最後一個問題:http://stackoverflow.com/questions/8023231/whats-wrong-with-my-javascript-code – Oded

回答

3

您可以動態地將腳本寫出到文檔中。

<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標籤頁上。

+2

這對於'document.write('

+0

@JaredFarrish - 公平點...想不想:) – Oded