javascript - 如何在php中选择一个时禁用下拉菜单

标签 javascript php html

有人可以帮我修复我的代码吗? 我的问题是如何在选择一个投递箱时禁用另一个投递箱? 我正在使用 PHP 和 JavaScript 编程语言。 我希望任何人都可以帮助我,因为这非常重要。

这是我的代码:

    <head>
           <script type = "text/javascript">
            function disableDrop(){
           if(frmMain.sltMain.options[1].selected){
                 frmMain.sltSecondary.disabled = true;
              }
              else{
                 frmMain.sltSecondary.disabled = false;
                }
              }
                   </script>
        </head>

         <form ID = "frmMain">

      <select ID = "sltMain" onchange = "disableDrop();">
         <option value = "onetime" selected>One-Time</option>
         <option value = "recurring">Recurring</option>
           </select>

         <select ID = "sltMain" onchange = "disableDrop();">
           <option value = "onetime">One-Time</option>
        <option value = "recurring" selected>Recurring</option>
         </select>
             </form>

最佳答案

试试这个:Demo

HTML 编码:

  <select ID = "sltMain" onchange = "disableDrop(this);">
     <option value = "onetime" selected>One-Time</option>
     <option value = "recurring">Recurring</option>
       </select>

     <select ID = "sltSecondary" onchange = "disableDrop1(this);">
       <option value = "onetime">One-Time</option>
    <option value = "recurring" selected>Recurring</option>
     </select>
         </form>

JAVASCRIPT:

function disableDrop(elem) {

    if(elem.value == 'recurring'){

    document.getElementById('sltSecondary').disabled = true;
    }
    else{
     document.getElementById('sltSecondary').disabled = false;        
    }

}
function disableDrop1(elem) {


    if(elem.value == 'onetime'){

    document.getElementById('sltMain').disabled = true;
    }
    else{
     document.getElementById('sltMain').disabled = false;        
    }

}

关于javascript - 如何在php中选择一个时禁用下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28500461/

相关文章:

javascript - 是否有任何解决方法可以重新抛出异常并保留 Javascript 中的堆栈跟踪?

javascript - 主干集合和多个 subview 设计问题

php - 插入两个表(同一个数据库)如何从一个表中获取唯一 ID?

html - 在 C++ linux 中使用 log4cplus 将日志写入 html 文件

javascript - 带有函数参数的方法链接

php - 如何删除已弃用的错误

php - 按顺序对输出进行编号

PHP 形式到 mySql 数据库。数组格式问题

javascript - 更改所选导出的文本输入背景颜色

html - weebly如何为每个页面设置不同的主要内容背景?