简体   繁体   English

下拉列表已更改

[英]drop down list changed

in my application I need to check if a drop down list has changed or not. 在我的应用程序中,我需要检查下拉列表是否已更改。 can you please let me know how I should write it? 你能让我知道我应该怎么写吗?

if (document.form.dropdownlist.???) 

I don't know what to write instead of ???? 我不知道该写些什么?

You could give this dropdownlist an unique id: 您可以为该下拉列表提供唯一的ID:

<select name="foo" id="foo">
    ...
</select>

and then subscribe for the onchange event (make sure you make the subscription once the DOM is loaded, for example in the body onload method): 然后订阅onchange事件(确保在DOM加载后立即进行订阅,例如在body onload方法中):

var ddl = document.getElementById('foo');
ddl.onchange = function() {
    alert('the value has changed');
};
var count=3;

 function check()
 {
    var obj =new Array();
    obj=document.getElementById("list");
    checkLength(obj.length);
 }
 function checkLength(len)
 {
    if(len>count)
    {
       alert("Drop down size changed");
    }
 }
  • Take three option elements in select element. 在选择元素中采用三个选项元素。
  • Call the method check() using onchange() to get the size of drop down list. 使用onchange()调用方法check()以获取下拉列表的大小。
  • The variable count is used to store the drop down list size . 变量计数用于存储下拉列表大小。
  • So that it can be used to check if drop down list is changed. 这样就可以用来检查下拉列表是否被更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM