Home Backend Development PHP Tutorial jQuery+PHP获取Select option 取舍的Text和Value(附选择城市实例)

jQuery+PHP获取Select option 取舍的Text和Value(附选择城市实例)

Jun 13, 2016 am 11:15 AM
nbsp quot select

jQuery+PHP获取Select option 选择的Text和Value(附选择城市实例)


PHP代码:

                 
Copy after login
  • 所在城市
  • 所在地区

  • Jquery代码:

            $("select.city").change(function(){            var ccode = $(this).val();            $("select.area").hide();            if(ccode){                $("select.area[citycode="+ccode+"]").show();            }        });        var sltcity = $("select.city").val();        if(sltcity){             $("select.area[citycode="+sltcity+"]").show();        }
    Copy after login

    下面是详细的:

    jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关设置

     

    获取一组radio被选中项的值:var item = $('input[name=items][checked]').val();
    获取select被选中项的文本:var item = $("select[@name=items] option[@selected]").text();

    获取select被选中项的文本 :var item = $("select[name=items] option[selected]").text(); 或$("select[name=items]").find("option:selected").text();

    select下拉框的第二个元素为当前选中值:$('#select_id')[0].selectedIndex = 1;

    select下拉框value = 'val'的元素为当前选中项:$("select[name=items] option[value='val']").attr("selected","selected");

    radio单选组的第二个元素为当前选中项 :$('input[@name=items]').get(1).checked = true; 或$('input[name=items]').attr("checked", '1′);

    radio的value = 'val'的元素为当前选中项:$('input[name=items] [value='val']').attr("checked","checked");


    获取值:

    文本框,文本区域:$("#txt").attr("value");

    多选框checkbox:$("input[name='checkbox':checked]").each(function(){

    var val = $(this).val();

    });

    单选组radio: $("input[type=radio][checked]").val();

    下拉框select的value值: $('select').val();

    下拉框select选中的text 值:$("select").find("option:selected").text();

    控制表单元素:

    文本框,文本区域:$("#txt").attr("value","); //清空内容

                           $("#txt").attr("value",'11′); //填充内容

    多选框checkbox:
    checkbox的第二个元素被打勾:$("input[name=items]").get(1).checked = true; //打勾
                                               $("input[name=items]").get(1).checked = false; //不打勾

    checkbox的value='val'的元素前打勾:$("input[name=item][value='val']").attr("checked",true); 或$("input[name=item][value='val']").attr("checked","checked");

    if($("input[name=item][value='val']").attr('checked')==true) //判断是否已经打勾

    单选组radio: $("input[type=radio]").attr("checked",'2′);//设置value=2的项目为当前选中项

    下拉框select: $("#sel").attr("value",'-sel3′);//设置value=-sel3的项目为当前选中项

    $("").appendTo("#sel")//添加下拉框的option

    $("#sel").empty();//清空下拉框

     

    jQuery获取Radio选择的Value值


    代码

    $("input[name='radio_name'][checked]").val(); //选择被选中Radio的Value值
    $("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发
    $("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发
    $("#text_id").select(); //使文本框的Vlaue值成选中状态
    $("input[name='radio_name'][value='要选中Radio的Value值'").
    attr("checked",true); //根据Value值设置Radio为选中状态

    jQuery获取CheckBox选择的Value值

    $("input[name='checkbox_name'][checked]"); //选择被选中CheckBox元素的集合 如果你想得到Value值你需要遍历这个集合
    $($("input[name='checkbox_name'][checked]")).
    each(function(){arrChk+=this.value + ',';});//遍历被选中CheckBox元素的集合 得到Value值
    $("#checkbox_id").attr("checked"); //获取一个CheckBox的状态(有没有被选中,返回true/false)
    $("#checkbox_id").attr("checked",true); //设置一个CheckBox的状态为选中(checked=true)
    $("#checkbox_id").attr("checked",false); //设置一个CheckBox的状态为不选中(checked=false)
    $("input[name='checkbox_name']").attr
    ("checked",$("#checkbox_id").attr("checked"));//根据3,4,5条,你可以分析分析这句代码的意思
    $("#text_id").val().split(","); //将Text的Value值以','分隔 返回一个数组

     

     jquery1.3.2

    ISDARK : $("input[@type=radio][name=ISDARK][checked]").val()

    $("input[name=radioname][value=radio值]").attr("checked","checked");



    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

    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 Article

    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Nordhold: Fusion System, Explained
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    Java Tutorial
    1671
    14
    PHP Tutorial
    1276
    29
    C# Tutorial
    1256
    24
    Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

    The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

    How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

    Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

    How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

    By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

    How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

    Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

    OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

    Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

    Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

    We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

    10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

    Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

    How to Fix Activation Error Code 0xc004f069 in Windows Server How to Fix Activation Error Code 0xc004f069 in Windows Server Jul 22, 2023 am 09:49 AM

    The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Go through these initial checks, and if they don't help you activate your system, jump to the main solution to resolve the issue. Workaround – close the error message and activation window. Then restart the computer. Retry the Windows activation process from scratch again. Fix 1 – Activate from Terminal Activate Windows Server Edition system from cmd terminal. Stage – 1 Check Windows Server Version You have to check which type of W you are using

    See all articles