Javascript 导航器 Cookie 测试不工作
Javascript Naviagtor Cookie Testing Not working
我正在尝试使用 Javascript Navigator 对象来测试是否在 browser.Im 中启用了 cookie,使用以下代码,显示了按钮,但点击后没有显示消息。
<!DOCTYPE html>
<html>
<body>
<p> Are cookies enabled ? </p>
<button onclick="myFunction()"> Button1 </button>
<p id="para1"></p>
<script>
function myFunction()
{
document.getElementbyId("para1").innerHTML="Cookies enabled is "+ navigator.cookieEnabled;
}
</script>
</body>
</html>
方法是.getElementById()
,不是.getElementbyId()
。如果您打开浏览器的控制台,您会看到如下内容:
TypeError: document.getElementbyId is not a function
http://jsbin.com/kixatozafu/1/edit
<!DOCTYPE html>
<html>
<body>
<p> Are cookies enabled ? </p>
<button onclick="myFunction()"> Button1 </button>
<p id="para1"></p>
<script>
function myFunction()
{
document.getElementById("para1").innerHTML="Cookies enabled is "+ navigator.cookieEnabled;
}
</script>
</body>
</html>
我正在尝试使用 Javascript Navigator 对象来测试是否在 browser.Im 中启用了 cookie,使用以下代码,显示了按钮,但点击后没有显示消息。
<!DOCTYPE html>
<html>
<body>
<p> Are cookies enabled ? </p>
<button onclick="myFunction()"> Button1 </button>
<p id="para1"></p>
<script>
function myFunction()
{
document.getElementbyId("para1").innerHTML="Cookies enabled is "+ navigator.cookieEnabled;
}
</script>
</body>
</html>
方法是.getElementById()
,不是.getElementbyId()
。如果您打开浏览器的控制台,您会看到如下内容:
TypeError: document.getElementbyId is not a function
http://jsbin.com/kixatozafu/1/edit
<!DOCTYPE html>
<html>
<body>
<p> Are cookies enabled ? </p>
<button onclick="myFunction()"> Button1 </button>
<p id="para1"></p>
<script>
function myFunction()
{
document.getElementById("para1").innerHTML="Cookies enabled is "+ navigator.cookieEnabled;
}
</script>
</body>
</html>