Basically, I have two dropdown lists on my page, both query the same database to populate themselves. What I want is for a use to be able to select an item in one of the dropdown lists, and then for the second dropdown list to show every other option except for what the user selected in the first dropdown list. I don't want the page to be refreshed in the process, and I want to avoid Sessions/Cookies if possible.

基本上,我的页面上有两个下拉列表,它们都查询相同的数据库以填充自己。我想要的是用于能够在其中一个下拉列表中选择项目,然后用于第二个下拉列表以显示除用户在第一个下拉列表中选择的内容之外的所有其他选项。我不希望在此过程中刷新页面,并且我希望尽可能避免使用会话/ Cookie。

The easiest way I can think to do this is by setting a variable when the user selects a thing in one of the lists, but I can't for the life of me figure out how to do this.

我能想到的最简单的方法是在用户选择其中一个列表中的东西时设置一个变量,但我不能在我的生活中找出如何做到这一点。

1 个解决方案

#1


HTML sample

<select id="select1" >
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>
<select id="select2" >
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>

Javascript

 $("#select1").change(function() {
        var val = $(this).val();
        $('#select2').children('option[value="' + val + '"]').attr('disabled', true);
        // or
        $('#select2').children('option[value="' + val + '"]').remove();
    })

JSFIddle sample

更多相关文章

  1. 手机端阻止页面滑动
  2. golang写服务端程序,作为文件上传与下载的服务器。配合HTML5以网
  3. JSP 或HTML 如何通过button按钮转到想去的页面
  4. 维护Java应用程序的多种形式的用户指南
  5. 我正在尝试使用带有post方法的AJAX将用户名和密码发送到php文件
  6. HTML5中window.postMessage,在两个页面之间的数据传递
  7. 在ios中,html5页面打电话
  8. 如何用DWR返回一个html页面?
  9. 在CSDN下载资源,扣了积分,下载的是一个404页面的html文件

随机推荐

  1. 为什么说 Python 内置函数并不是万能的?
  2. 如何处理偏态数据?
  3. SQL今日一题(6):count
  4. Python有序字典的两个小“惊喜”~~
  5. 学习SQL:MySQL必知必会
  6. 醒醒!Python已经支持中文变量名啦!
  7. Python 幕后解释器:一系列的学习资源
  8. SQL每日一题
  9. 再说相关性分析
  10. SQL今日一题(7):去重