-2
我有一個文件,這個JavaScript代碼名爲cookies.js如何調用JavaScript函數?
function setCookie(cname, cvalue, exdays)
{
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
我的HTML文件看起來像:
<html>
<head>
<script type="text/javascript" src="cookies.js">
//how to call the function
</script>
</head>
</html>
我怎麼能叫帶參數的SetCookie函數。
您包含該文件,然後添加另一個腳本標記並像往常一樣調用'setCookie'。 – Li357
您的代碼的來源位於:https://www.w3schools.com/js/js_cookies.asp –