• 利用jquery获取html中被选中的input的值


    单个按钮

    <div id="wrap">
    <input type="radio" name="payMethod" value="1" />支付宝
    <input type="radio" name="payMethod" value="2" />财务通
    </div>
      
      获取一组单选按钮对象:var obj_payPlatform = $('#wrap input[name="payMethod"]');
      获取被选中按钮的值 :var val_payPlatform = $('#wrap input[name="payMethod"]:checked ').val();

    多个按钮

    1. 创建Html元素

      <div class="box">
      <span>点击按钮获取checkbox的选中值:</span><br>
      <div class="content">
         <input type='checkbox' name='message' value='1'/>发送短信
             <input type='checkbox' name='message' value='2'/>发送邮件
      </div>
      <input type="button" value="提交">
      </div>
    2. 设置css样式

      div.box{300px;padding:20px;margin:20px;border:4px dashed #ccc;}
      div.box>span{color:#999;font-style:italic;}
      div.content{250px;margin:10px 0;padding:20px;border:2px solid #ff6666;}
    3. 编写jquery代码

      $(function(){ 
      $("input:button").click(function() {
      text = $("input:checkbox[name='message']:checked").map(function(index,elem) {
      return $(elem).val();
      }).get().join(',');
      alert("选中的checkbox的值为:"+text);
      });
      });
  • 相关阅读:
    静态链接与动态链接的区别(转载)
    VC++界面编程之--阴影窗口的实现详解
    win7 vmware 无法使用usb
    如何划分子网,确定子网和掩码的位数?
    华为三层交换机-路由-硬件防火墙的配置
    jquery json ajax -2
    jquery json ajax
    wes开发笔记
    伪类和伪元素
    优化sql语句
  • 原文地址:https://www.cnblogs.com/zzc134680/p/5652303.html
Copyright © 2020-2023  润新知