0

我创建了以下下拉列表以及将输出“块”-> 与选项关联的详细信息的条件检查。见下文,例如:

function val(ddbox) {

         //NEW
        if ( ddbox.options[ddbox.selectedIndex].value == "Others"){
                document.getElementById("extradiv").style.display = "block";
        }else{
                document.getElementById("extradiv").style.display = "none";
        }
         if( ddbox.options[ddbox.selectedIndex].value != "Others"){
                document.getElementById("NumberChosen").style.display = "block";
        }else{
                document.getElementById("NumberChosen").style.display = "none";
        }
}
 <li class="bigfield">
                        <select name ="ddbox" id="ddbox" onchange = "val(this)">
                        <option value ="0"> Select Number..</option>
                        <option value ="Option 1"> 1</option>
                        <option value ="Option 2"> 2</option>
                        <option value ="Option 3"> 3</option>
                        <option value = "Others"> Others</option>
                        </select>
                </li>


                <!--when user select "Others"-->
                <div id = "extradiv" style ="display:none">
                <li class="bigfield"><input placeholder="Enter your Num" type="text" name="OthersNum" id="OthersNum"/></li>
                <li class="bigfield"><input placeholder="Number Characteristics" type="text" name="NumberOthersCharacteristics" id="NumberOthersCharacteristics"/></li>
                <li class="bigfield"><input placeholder="why do you like this number" type="text" name="NumberOthersLikefactor" id="NumberOthersLikefactor"/></li>
                 </div>

                 <!--when user select other options-->
                <div  id = "NumberChosen" style ="display:none" >
               <li class="bigfield"><input value="NumChosen" type="text" name="NumChosen" id="NumChosen" readonly></li>
                <li class="bigfield"><input value="Num Chosen Characteristic" type="text" name="NumChosenCharactersitics" id="NumChosenCharactersitics" readonly/></li>
                <li class="bigfield"><input value="Num Chosen Likes" type="text" name="NumChoseLikes" id="NumChoseLikes" readonly/></li>
                 </div>

我已将每个选择的选项都引用到中的详细信息,当用户单击“其他”时,它将引用 . 因此,字段表单是在 MVC 框架的视图中完成的。

为确保在提交时将值正确 POST 到控制器代码,我在控制器代码中创建了以下错误日志,以检查从表单捕获的值。以下error_logs如图所示:

       error_log(date("Y-m-d H:i:s")."_ipad,Num: ".$_POST['OthersNum']."\n",3,"/var/tmp/*/*.log");
       error_log(date("Y-m-d H:i:s")."_-ipad, NumChar: ".$_POST['NumberOthersCharacteristics']."\n",3,"/var/tmp/*/*.log");
       error_log(date("Y-m-d H:i:s")."_-ipad, NumLikes: ".$_POST['NumberOthersLikefactor']."\n",3,"/var/tmp/*/*.log");

       error_log(date("Y-m-d H:i:s")."_-ipad,NumberChosen: ".$_POST['NumChosen']."\n",3,"/var/tmp/*/*.log");
       error_log(date("Y-m-d H:i:s")."_-ipad, NumChosenChar: ".$_POST['NumChosenCharacteristics']."\n",3,"/var/tmp/*/*.log");           error_log(date("Y-m-d H:i:s")."_-ipad, NumChosenLikes: ".$_POST['NumChoseLikes']."\n",3,"/var/tmp/*/*.log");

现在,这是我面临的主要问题,当我运行以下终端命令时,两个错误日志都将始终显示:'tail -f *.log',例如,如果我在选项中选择“其他”列出并键入相应的字段,然后提交表单,值将 POST 到控制器代码,错误日志不仅会显示“OthersNum”的值,还会显示 NumChosen 的详细信息。这不是我想要的结果,我正在查看错误日志,只发布为“其他”选项输入的详细信息,而不显示与其他选项相关的详细信息

因此,根据我的理解,显示了冗余的 error_log ,表单中的所有值都是 POST 到控制器的。因此,我如何能够编辑现有代码,以便仅将选定的选项发布到控制器?

4

1 回答 1

0

我认为你的问题来自 if 语句,你不想在相同的条件下使用多个 if 语句,你的 if 语句应该是,

function val(ddbox) {
        if ( ddbox.options[ddbox.selectedIndex].value == "Others"){
                document.getElementById("extradiv").style.display = "block";
               document.getElementById("NumberChosen").style.display = "none";
        }else{
                document.getElementById("extradiv").style.display = "none";
                document.getElementById("NumberChosen").style.display = "block";
        }
}

对类似条件使用单个 if 语句,希望这有效...

于 2015-09-11T05:02:55.250 回答