jQuery监控select的变化

怎样通过jQuery监控select(也就是选择框,可以是单选也可以是多选)的变化?
其实还是很方便的.

 

 
主要使用了change 函数,然后通过Selected 这个来看是否选中改元素
#service 为Select box 的ID

 

 

代码如下

$("#service").change(function(){
    var str = "";
    $( "#service option:selected" ).each(function() {
        str += $( this ).text() + "\n";
    });
    alert(str);
})

 

 

 

 

这篇博文发表在 网页设计 | Web Design 目录下,标签为 , , ,
如需引用,请使用链接:https://note.mc256.dev/?p=171

This article published in 网页设计 | Web Design with tags , , , .
Cite this page using this link:https://note.mc256.dev/?p=171

您的邮箱地址不会被公开,评论使用Gravatar头像。
Your email address will not be published. This blog is using Gravatar.

正在提交评论... Submitting ...
正在为您准备评论控件 Loading Comment Plugin
Copyright © 2013-2023 mc256. All Rights Reserved.
Powered by WordPress on top of a dual-stack HA k3s Cluster using Etcd + JuiceFS + CloudNativePG.
Wordpress Theme Designed By mc256.
Encrypted By Let's Encrypt.  Hosted On Linode + OVH + AWS.
DNS Provided By Hostker.
Status Page by CloudFlare Worker.