Home  >  Article  >  Web Front-end  >  Specify the method of assigning values ​​to the drop-down box

Specify the method of assigning values ​​to the drop-down box

php中世界最好的语言
php中世界最好的语言Original
2018-04-13 11:43:549165browse

This time I will bring you how to assign a value to the drop-down box. What are the precautions for assigning a value to the drop-down box? The following is a practical case, let's take a look.

jsImplementation:

1. Select the i-th option by letting it be selected. The code is as follows: (id is the drop-down box id)

(1) document.getElementById("id").options[i].selected=true;

(2) document.getElementById("messagetoid").selectedIndex = 1; (Select the first option)

2. This is achieved by judging the value of option. The code is as follows:

document.getElementById("messagetoid").value=""; (select the option whose value is empty)

jQueryImplementation:

1. By selecting the i-th option, similar to js implementation 1, the code is as follows:

$("#id").get(0).selectedIndex =

1;(Select the first option)

2. To achieve this by judging the value of option, there are two methods. The code is as follows:

(1) $("#id").val("123"); (Select the option with value "123")

(2) $("#messagetoid").attr("value", ""); (Select the option whose value is empty)

EasyUI implementation:

$('#id').combobox('setValue','A'); (Select the option whose value is A,)

I believe you have mastered it after reading the case in this article For more exciting methods, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps for using slot and slot-scope in vue

Removing the marker overlay on Baidu map Methods

The above is the detailed content of Specify the method of assigning values ​​to the drop-down box. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn