使用JavaScript我将网页中的名称拉出来并以某种方式将它们串在一起(可能与数组一起).一旦我将所有名称收集在一起,我需要创建另一个字符串,该字符串提供名称的所有电子邮件地址.电子邮件地址不在网页上,所以我必须在我的脚本中以某种方式列出每个可能的thisName = thisEmail.我打算通过制作一个无数的if语句来解决这个问题,但我认为必须采用更有效的方式.有什么建议?
var x = getElementById("names");
var name = x.InnerHTML;
var email;
if (name == 'Steve'){ email == 'steve462@gmail.com'; }
if (name == 'Bob'){ email == 'duckhunter89@gmail.com'; }
....
Run Code Online (Sandbox Code Playgroud) 我有以下代码,这取决于url参数更改,然后隐藏表单上的选择选项.即www.example.com?type=images
最终将有超过20个不同的参数.我想知道一个更好的方法,而不是拥有大量的elses.只是概述了如何做到这一点很好,我是新手,所以我希望能够得到答案并从中学习.谢谢.
var type = getURLparameter('type'); //from another function
if (type == "images"){
var selectDiv =('divid');
var selectField = ('selectid');
document.getElementById(selectField).options[1].selected=true;
document.getElementById(selectDiv).style.visibility="hidden";
}
else if (type == "pizza") {
var selectDiv =('divid');
var selectField = ('selectid');
document.getElementById(selectField).options[2].selected=true;
document.getElementById(selectDiv).style.visibility="hidden";
}
else (type == "cheese") {
var selectDiv =('divid');
var selectField = ('selectid');
document.getElementById(selectField).options[3].selected=true;
document.getElementById(selectDiv).style.visibility="hidden";
}
Run Code Online (Sandbox Code Playgroud)