作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 javascript 的初学者,我正在尝试在给定的条件下弹出一个警报框。但是,我的代码中没有任何内容弹出。页面刷新,网址栏包含我在表单中输入的信息。我的代码有什么问题吗?
function validateform(form)
{
var self = 1;
var spouse = 1;
var mom = 1;
var dad = 1;
var educ = 1;
var work = 1;
var elig = 1;
if((form.country.value == "Bangladesh" || form.country.value == "Brazil" || form.country.value == "Canada" || form.country.value == "China" || form.country.value == "Colombia" || form.country.value == "Dominican Republic" || form.country.value == "Ecuador" || form.country.value == "El Salvador" || form.country.value == "Haiti" )|| (form.country.value == "India" || form.country.value == "Jamaica" || form.country.value == "Mexico" || form.country.value == "Nigeria" || form.country .value == "Pakistan" || form.country.value == "Peru" || form.country.value == "Philippines" || form.country.value == "South Korea" || form.country.value == "United Kingdom" || form.country.value == "Vietnam"))
{
self = 0;
}
if((form.countryspouse.value = '' || form.countryspouse.value == "Bangladesh" || form.countryspouse.value == "Brazil" || form.countryspouse.value == "Canada" || form.countryspouse.value == "China" || form.countryspouse.value == "Colombia" || form.countryspouse.value == "Dominican Republic" || form.countryspouse.value == "Ecuador" || form.countryspouse.value == "El Salvador" || form.countryspouse.value == "Haiti" )|| (form.countryspouse.value == "India" || form.countryspouse.value == "Jamaica" || form.countryspouse.value == "Mexico" || form.countryspouse.value == "Nigeria" || form.countryspouse.value == "Pakistan" || form.countryspouse.value == "Peru" || form.countryspouse.value == "Philippines" || form.countryspouse.value == "South Korea" || form.countryspouse.value == "United Kingdom" || form.countryspouse.value == "Vietnam"))
{
spouse = 0;
}
if((form.countrydad.value == "Bangladesh" || form.countrydad.value == "Brazil" || form.countrydad.value == "Canada" || form.countrydad.value == "China" || form.countrydad.value == "Colombia" || form.countrydad.value == "Dominican Republic" || form.countrydad.value == "Ecuador" || form.countrydad.value == "El Salvador" || form.countrydad.value == "Haiti" )|| (form.countrydad.value == "India" || form.countrydad.value == "Jamaica" || form.countrydad.value == "Mexico" || form.countrydad.value == "Nigeria" || form.countrydad.value == "Pakistan" || form.countrydad.value == "Peru" || form.countrydad.value == "Philippines" || form.countrydad.value == "South Korea" || form.countrydad.value == "United Kingdom" || form.countrydad.value == "Vietnam"))
{
dad = 0;
}
if((form.countrymom.value == "Bangladesh" || form.countrymom.value == "Brazil" || form.countrymom.value == "Canada" || form.countrymom.value == "China" || form.countrymom.value == "Colombia" || form.countrymom.value == "Dominican Republic" || form.countrymom.value == "Ecuador" || form.countrymom.value == "El Salvador" || form.countrymom.value == "Haiti" )|| (form.countrymom.value == "India" || form.countrymom.value == "Jamaica" || form.countrymom.value == "Mexico" || form.countrymom.value == "Nigeria" || form.countrymom.value == "Pakistan" || form.countrymom.value == "Peru" || form.countrymom.value == "Philippines" || form.countrymom.value == "South Korea" || form.countrymom.value == "United Kingdom" || form.countrymom.value == "Vietnam"))
{
mom = 0;
}
if(form.education.value == "noeducation")
{
educ = 0;
}
if(form.occupation.value == "None")
{
work = 0;
}
if(((educ + work) == 0 )||((self + spouse + parents) == 0 ))
{
alert("Sorry, you are ineligible.");
}else
{
alert("You are eligible.");
}
}
最佳答案
“ parent ”未定义
如果您查看控制台,您会发现您在 if
语句中使用了“parents”,但它并不存在。
如果您删除 parents
或添加 varparents = 1;
它将起作用。
您还应该查看您的 if
语句。您使用的是单个等于 =
,而不是双 ==
或三重 ===
等于。
Single 将设置一个值,double 和 Triple 将进行比较 - 唯一的区别是,对于 Triple,它们也必须是相同的类型才能返回 true。
例如
1 = 1 -- will set int 1 with a value of 1
1 == "1" -- will return true (int compared to a string)
1 === "1" -- will return false (int compared to a string)
关于javascript - 我试图在 javascript 中弹出警报,但没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629482/
我是一名优秀的程序员,十分优秀!