Home > Web Front-end > JS Tutorial > How to make the select unselected in jquery

How to make the select unselected in jquery

藏色散人
Release: 2020-12-22 10:37:37
Original
2477 people have browsed it

The implementation method of jquery to uncheck the select: first open the corresponding code file; then set the disabled attribute to disabled through the "attr()" method; finally run the code to see the effect of the select drop-down box being unchecked.

How to make the select unselected in jquery

The operating environment of this tutorial: Windows 7 system, jquery3.3.1 version. This method is suitable for all brands of computers.

Related recommendations: "jquery video tutorial"

jquery makes select unselected:

In jquery, set select The drop-down box is not selectable and unchecked, mainly by setting the disabled attribute to disabled through the attr() method.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        select{  /*为了看到效果这里添加了宽和高*/
            width:100%;
            height:100px;
            margin:100px 0;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
    <div id="div1">
        <select id="select1">
            <option value="1">我是第一个option</option>
            <option value="2">我是第二个option</option>
            <option value="3">我是第三个option</option>
            <option value="4">我是第四个option</option>
        </select>
    </div>
    <div id="select2">
        <select>
            <option value="1">我是第一个option</option>
            <option value="2">我是第二个option</option>
            <option value="3">我是第三个option</option>
            <option value="4">我是第四个option</option>
        </select>
    </div>
    <script>
        $(function(){
            $("select").each(function () {
                $(this).attr("disabled","disabled");
            });
        });
    </script>
</body>
</html>
Copy after login

Rendering:

How to make the select unselected in jquery

Instructions:

In this way, add disabled="disabled" directly to the select tag through the attr() method Property to disable select so that the select tag cannot be expanded and therefore cannot be selected.

The above is the detailed content of How to make the select unselected in 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