Home > Web Front-end > JS Tutorial > How to implement specified assignment method using js and jQuery

How to implement specified assignment method using js and jQuery

亚连
Release: 2018-06-09 18:10:53
Original
1725 people have browsed it

Now I will share with you an article about js, jQuery and easyui to implement the designated value assignment method for the drop-down box. It has a good reference value and I hope it will be helpful to everyone.

js implementation:

#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 the option. The code is as follows:

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

jQuery implementation:

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

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

1; (Select the first option)

2. By judging the value of the 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,)

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to solve the practical problem of easyui date and time box ie compatibility (detailed tutorial)

Explain to you in detail Practical skills in Immutable and React

How to solve the error problem on VUEX compatible IE (detailed tutorial)

The value cannot be observed in Vuex What is the solution to change?

How to use readline in Node.js to read and write file contents line by line

How to use readline in Node.js Modules and util modules

Detailed explanation of using Node.js to write a simple command line tool (detailed tutorial)

In Node.js Use cheerio to make a simple web crawler (detailed tutorial)

How to implement parent components to pass multiple data to child components in vue

In How to solve the problem of being unable to dynamically modify the URL address of jqgrid component in vue

How to use Native in React to implement custom pull-down refresh to pull-up loaded list

The above is the detailed content of How to implement specified assignment method using js and jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template