简体   繁体   中英

How can I check if a value already exists in a ListBox in Java Script

The Answer for the code behind was given as follows:

if (!listBoxInstance.Items.Contains("some text")) // case sensitive is not important
            listBoxInstance.Items.Add("some text");
if (!listBoxInstance.Items.Contains("some text".ToLower())) // case sensitive is important  
            listBoxInstance.Items.Add("some text".ToLower());

Now how would this be done in Java Script? TIA.

Is this listBox.items an object? If so:

if (!listBoxInstance.Items["some text"]) // case sensitive is not important
            listBoxInstance.Items["some text"] = // the value of the property you want to assign;
if (!listBoxInstance.Items[`${"some text".toLowerCase()}`]) // case sensitive is important  
            listBoxInstance.Items[`${"some text".toLowerCase()}`);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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