Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML/Javascript&&;If语句中的条件_Javascript_Html_If Statement_Radio Button - Fatal编程技术网

HTML/Javascript&&;If语句中的条件

HTML/Javascript&&;If语句中的条件,javascript,html,if-statement,radio-button,Javascript,Html,If Statement,Radio Button,我相信有一个非常简单的解决办法,我很可能没有尽可能以最有效的方式来解决这个问题 我正在尝试创建一个if语句,该语句将检查是否在多个问题中选择了多个单选按钮。如果选择了它们,我希望弹出一个带有特定消息的警报框。可能会有许多选择组合,因此我假设有许多if/else语句(?) 讨论中的Javascript位于底部 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> &l

我相信有一个非常简单的解决办法,我很可能没有尽可能以最有效的方式来解决这个问题

我正在尝试创建一个if语句,该语句将检查是否在多个问题中选择了多个单选按钮。如果选择了它们,我希望弹出一个带有特定消息的警报框。可能会有许多选择组合,因此我假设有许多if/else语句(?)

讨论中的Javascript位于底部

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Spigit Input Form</title>
  <meta name="description" content="Spigit Input Form">
  <meta name="author" content="SitePoint">

  <link rel="stylesheet" href="css/styles.css?v=1.0">
  <link rel="stylesheet" href="Project_File_CSS.css">

  <!--[if lt IE 9]>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
  <![endif]-->

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="jquery_spigit.js"></script>
</head>

<body>

  <!--<script src="js/scripts.js"></script>
  <script src="New_File_JS.js"></script>-->
  <script type="text/javascript" src="selection_storage.js"></script>
  <!--<script type="text/javascript" src="recommendation_logic.js"></script>-->

<!---------------------------------------------------------Operating Company Question----------------------------------->
<form name="operatingCompany">
<h3>What Operating Company Are You Employeed With?</h3>
<input type="radio" name="opco" value="GPC" >GPC</br>
<input type="radio" name="opco" value="APC" >APC</br>
<input type="radio" name="opco" value="MPC" >MPC</br>
<input type="radio" name="opco" value="Gulf" >Gulf</br>
<input type="radio" name="opco" value="SCS" >SCS</br></br>

<input type="button" value="Display User Selection" onclick=get_opco() />
</form>

<p id="opco_result"> </p></br>


<!---------------------------------------------------------Prototyped Question----------------------------------->
<form name="prototyped">
<h3>Has the innovation been prototyped?</h3>
<input type="radio" name="prototyped" value="Yes" >Yes</br>
<input type="radio" name="prototyped" value="No" >No</br></br>

<input type="button" value="Display User Selection" onclick=get_prototype() />
</form>

<p id="prototyped_result"> </p></br>

<!--------------------------------------------------------Adopted or Tested Question---------------------------->
<form name="adopted_tested">
<h3>Has the innovation been adobpted or tested?</h3>
<input type="radio" name="adopt" value="Yes" >Yes</br>
<input type="radio" name="adopt" value="No" >No</br></br>

<input type="button" value="Display User Selection" onclick=get_adopt_test() />
</form>

<p id="adopted_tested_result"> </p></br>

<!------------------------------------------------------Can it make money Question------------------------------->
<form name="makeMoney">
<h3>Is this a product or service that can make money?</h3>
<input type="radio" name="money" value="Yes" >Yes</br>
<input type="radio" name="money" value="No" >No</br></br>

<input type="button" value="Display User Selection" onclick=get_money() />
</form>

<p id="makeMoney_result"> </p></br>

<!---------------------------------------------------Alabama Power Specific Question----------------------------->
<h3>What is your innovative idea to help Alabama Power improve safety, grow revenue, reduce cost, or increase operational efficiency?</h3>
<textarea id="alabamaPower" rows="8" cols="50">

</textarea> </br></br>

<input type="button" value="Display User Input" onclick=textareacapture() />

<p id="result"> </p></br>

<!------------------------------------------------IT Specific Question------------------------------------------->
<form name="innovativeTechnology">
<h3>Is your innovation an innovative technology or process that boosts the company's productivity or brings additional value from a vendor relationship?</h3>
<input type="radio" name="innovative" value="Yes" >Yes</br>
<input type="radio" name="innovative" value="No" >No</br></br>

<input type="button" value="Display User Selection" onclick=get_innovative() />
</form>

<p id="innovativeTechnology_result"> </p></br>

<input type="button" value="Submit Form" onclick=get_recommendation() />

<script>
function get_recommendation(){
        if((document.operatingCompany.opco[0,1,2,3,4].checked) && (document.prototyped.prototyped[0,1].checked) && (document.adopted_tested.adopt[0,1].checked))
        {
            alert("Everyday Solutions");
        }       
}
</script>

</body>
</html>

Spigit输入表单
你受雇于哪家运营公司?
GPC
APC
MPC
海湾
SCS


创新是原型化的吗? 对
没有


创新是否已被采用或测试? 对
没有


这是一种可以赚钱的产品或服务吗? 对
没有


您有什么创新想法来帮助阿拉巴马电力公司提高安全性、增加收入、降低成本或提高运营效率?


您的创新是否是一种创新技术或流程,可以提高公司的生产率或从供应商关系中带来附加价值? 对
没有


函数get_recommendation(){ if((document.operatingCompany.opco[0,1,2,3,4]。选中)和(document.prototype.prototype[0,1]。选中)和(document.adopted\u tested.adoption[0,1]。选中)) { 警报(“日常解决方案”); } }
您是否在运行时检查了if中变量的值?此外,当前您正在检查是否已检查所有这些选项。是否要检查是否已检查其中一些


另外,您确定要使用警报吗。模态分析确实更可取。警报将阻止事件循环。

使用此测试确定是否已检查任何单选按钮:

($(":checked").length > 0)
如果您只对页面上的单选按钮或复选框的子集感兴趣,则可以优化选择器

逻辑and(&&)

if(x>5&&x那么像PHP/C这样的中间层呢

if (5 < x < 10) {
    ...
}
if(5
欢迎使用Stack Overflow!这实际上是一条评论,而不是一个答案。需要更多的代表性,请参阅以获取解释。@TheOracle他没有足够的代表性。如果第一个问题中选中了“是”,第二个问题中选择了“是”,那么我想输出一条特定的消息。另一个示例:如果在第一个问题中选择了“有”t问题,在后两个问题中选择“否”,在第四个问题中选择“是”,然后我想显示不同的输出。仅供参考,
document.operatingCompany.opco[0,1,2,3,4]
相当于
document.operatingCompany.opco[4]
。这是一个,它不会自动将操作映射到多个下标。那么像
如果(5
哈哈,这个if条件总是运行true块,因为你的条件在逻辑上是false,这意味着不可能。这似乎可行(或者至少让我更接近我的目标):
$(document).ready(函数(){if($('input[name=“opco”]:checked')){alert(“它工作”);}});
但是,仍然存在以下问题:(1)页面加载时会出现警报框(2)即使未选中单选按钮,警报框也会出现。我希望Submit Form按钮触发警报框。re 1.)和re 2.)在
if
语句中,您必须测试jQuery对象的
length
属性。无论选择器是否匹配,都会构造此对象。因此,对对象的测试总是会产生一个真实的值,因此警报框总是显示。(re 3。)如果您希望submit按钮触发警报,请使用
If
语句中的条件来保护
GetRecommension
中的警报。
if (5 < x < 10) {
    ...
}