0
我正在構建一個C#應用程序(WinForm)。我有一個javascript組件可以改變網頁的背景顏色。如果我把JS直接放到它的HTML文件中(即web瀏覽器的背景顏色顯示爲紅色)。JavaScript資源不運行在WebBrowser控件(WinForm)
<!DOCTYPE html>
<<HTML>
<HEAD>
<TITLE>Title</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<HR>
<script>
var setBackColor = function() {
document.body.style.backgroundColor = "red";
}
setBackColor();
</script>
<H1>This is a Header</H1>
<H2>This is a Medium Header</H2>
<P> This is a new paragraph!
<P>
<B>This is a new paragraph!</B>
<BR><B><I>This is a new sentence without a paragraph break, in bold italics.</I></B><BR>
<HR>
</BODY>
</HTML>
當我把JS在外部文件中,並嘗試通過所示,我得到的是一條錯誤的路徑訪問它...
「屬性‘setBackColor’的值爲null或未定義,而不是函數對象。「
<!DOCTYPE html>
<<HTML>
<HEAD>
<TITLE>Title</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<HR>
<script type="text/javascript" src=c:\users\local user\documents\visual studio 2015\Projects\HTMLTestApp\HTMLTestApp\Scripts\JavaScript1.js></script>
<body onload="setBackColor()"></body>
<H1>This is a Header</H1>
<H2>This is a Medium Header</H2>
<P> This is a new paragraph!
<P>
<B>This is a new paragraph!</B>
<BR><B><I>This is a new sentence without a paragraph break, in bold italics.</I></B><BR>
<HR>
</BODY>
</HTML>
我是一個完整的新手編碼器,所以我不知道我在做什麼錯。