我试图让这个函数验证2输入字段的值;即字母和网站,但它不起作用,我不知道我做错了什么。
/ *功能* /
function access()
{
if(document.getElementById('letters').value=='man' && ('website').value=='mann')location.href='http://www.google.com'
else if(document.getElementById('letters').value=='woman')location.href='http://www.dynamicdrive.com'
else if(document.getElementById('letters').value=='cat')location.href='http://www.youtube.com'
else if(document.getElementById('letters').value=='dog')location.href='http://www.dailymotion.com'
else alert('Access denied. Try again.')
}
/ *表格* /
<div id="cliente">
<form>
<input type='text' class="clientelog" id='website' value="Website"> </input>
<input type='text' class="clientelog" id='letters' value="Code" >
</input>
<input class="checkerbttn" type='button' onclick='access()' value='show me' ></input>
</form>
</div><!-- End Cliente -->
答案 0 :(得分:2)
从您发布问题时可能只是一个复制粘贴错误,但这一行是错误的:
if(document.getElementById('letters').value=='man' && ('website').value=='mann') location.href='http://www.google.com'
// ----------------------------------problem is here--^
您已('website').value
document.getElementById('website').value