search
Homephp教程PHP开发jquery select select drop-down menu option item trigger event

The select drop-down menu option item triggered by jquery implements an event:
In many applications, selecting a select drop-down option will trigger an event and perform the corresponding operation.
The following is a code example to introduce how to use jquery to implement this function. The code is as follows:

<!DOCTYPE html><html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>蚂蚁部落</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(document).ready(function () { 
  $("#sel").bind("change",function(){ 
    if($(this).val()==0){
      return; 
    } 
    else{
      $("#thediv").text($(this).val());
    } 
  }); 
});
</script> 
</head> 
<body>
<div id="thediv"></div>
<select id="sel">
  <option value="0">-请选择-</option> 
  <option value="1">蚂蚁部落一</option> 
  <option value="2">蚂蚁部落二</option> 
  <option value="3">蚂蚁部落三</option> 
  <option value="4">蚂蚁部落四</option> 
</select>
</body>
</html>

The above code selects all options except the first item and writes the value into the div.


For more jquery selection select drop-down menu option items trigger events, please pay attention to the PHP Chinese website for related articles!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft