JavaScript和复选框不起作用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JavaScript和复选框不起作用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4581字,纯文字阅读大概需要7分钟。
内容图文
![JavaScript和复选框不起作用](/upload/InfoBanner/zyjiaocheng/663/64c0bf1bbf8149b6849979a2b2cff572.jpg)
基本上,我试图用HTML制作一个表单,该表单使用JavaScript从复选框中获取输入,并根据选中的复选框打开我网站上的特定页面.
当我选中一个框或不选中一个框或更多框时,它仅通过发出警报来响应,请选中一个框.有人对我缺少的东西有任何想法吗?目前,这是我尝试多种不同方式后编写代码的方式.还要注意,我在相同文件夹的html页面中有我要打开的指定窗口.
JavaScript:
function checking()
{
var frm = document.diaglab;
var majdep1 = document.getElementById("majdep").checked;
var bipolar1 = document.getElementsByName("bipolar").checked;
if(majdep1.checked == true && bipolar1.checked == true)
{
window.alert("possible bipolar disorder");
window.open("bipolar1.html");
}else{
window.alert("please check boxes");
}
}
HTML代码:
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta name="" content="">
<link href="illness.css" rel="stylesheet">
<script type="text/javascript" src="checked.js"></script>
</head>
<body>
<div id="container">
<div >
<h1 id="mainhead">Exploring Symptoms</h1>
</div>
<div>
<article ><p>This exploring area is just a lab tool that allows you too explore how mental illness is diagnosed<br />
according to the DSM V. You can click on certain symptoms and see what diagnoses may be applied. It<br />
is important to know that this is not an actual diagnosis tool and should not be applied to your life in any<br />
way as to self diagnose, treat or medicate yourself or anyone else. If you feel that you may be suffering<br />
from a mental illness contact your physician! Also note that this tool is not all inclusive and if you want<br />
a deeper understanding please refer to the DSM V.</p></article>
</div>
<hr>
<div id="explrfrm">
<form name="diaglab" method="post" onsubmit="return checking()">
<label id="explrlab">Depressive and Manic Symptoms</label><br />
<span id="explrlab1">
<label id= title="Symptom1" >1. Depressed mood (sad, empty, hopeless)most of the day, nearly everyday.</label> <input type="checkbox" name="majdep" id="majdep" ><br /><br />
<label title="Symptom2">2. Diminished interest or pleasure in all or nearly all activities</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom3">3. Significant weight loss or gain (without dieting) or decreased appetite most days.</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom4">4. Insomnia (inability to sleep) or Hypersomnia (sleeping too much) nearly everyday</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom5">5. Fatigue or loss of energy almost everyday</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom6">6. Feelings of worthlessness or excessive and inappropriate guilt.</label> <input type="checkbox" name="majdep" is="majdep"><br /><br />
<label title="Symptom7">7. Diminished ability to think, concentrate, or indecisiveness.</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom8">8. Recurrent thoughts of death, suicidal ideations with or without a plan and or attempt.</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom9">9. significant impairment in social , occupational, or other important areas of functioning</label> <input type="checkbox" name="majdep" id="majdep"><br /><br />
<label title="Symptom10">10. Distinct period of abnormally or persistent elevated, expansive, or irritable mood and increased goal directed energy for at least one week all day or nearly all day</label> <input type="checkbox" name="bipolar" id="bipolar"><br /><br />
<label title="Symptom11">11. During the period of increased mood energy at least three of the following: inflated self esteem, dcreased need for sleep, extreme talkitivity, flight of ideas,distractibility, increased goal directed activity, or excessive activity involvement nearly everyday.</label> <input type="checkbox" name="bipolar" id="bipolar"><br />
</span>
<input type="submit" value="submit">
<input type="reset" value="Reset">
</form>
</div>
</div>
</body>
</html>
解决方法:
您的代码有误
在定义变量时,以及在执行if语句时,都已引用.checked.
以下应该工作
function checking()
{
var frm = document.diaglab;
// This is incorrect! You have .checked at the end!
//var majdep1 = document.getElementById("majdep").checked;
//var bipolar1 = document.getElementsByName("bipolar").checked;
var majdep1 = document.getElementById("majdep");
var bipolar1 = document.getElementsById("bipolar");
if(majdep1.checked == true && bipolar1.checked == true)
{
window.alert("possible bipolar disorder");
window.open("bipolar1.html");
}else{
window.alert("please check boxes");
}
}
内容总结
以上是互联网集市为您收集整理的JavaScript和复选框不起作用全部内容,希望文章能够帮你解决JavaScript和复选框不起作用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。