zoukankan      html  css  js  c++  java
  • 为html select添加自定义属性

    https://stackoverflow.com/questions/46600612/html-select-onchange-get-custom-attribute-value-set-to-other-input-value

    $(function() {
      $('select.form-control').change(function() {
        var typeId = $(this).find('option:selected').data('typeid');
        $("#money").val(typeId);
      }).change();
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <select class="form-control">
      <option data-typeid="1111" value="courseId1">courseName1</option>
      <option data-typeid="2222" value="courseId2">courseName2</option>
    </select>
    
    <input type="number" value="" id="money" class="form-control">

    示例:

    <select style="position:relative; z-index: 100; pointer-events: all;" name="addEntity" id="addEntity">
                      <option data-typeid="1111" data-resourcename="小轿车01" value ="car">汽车</option>              
                      <option data-typeid="2222" data-resourcename="大叶伞01" value ="tree"></option>
                      <option data-typeid="3333" data-resourcename="枪式摄像头01" value ="camera">摄像头</option>
                      <option data-typeid="4444" data-resourcename="草坪灯01" value ="">传感器</option>
                    </select>
    
    
    
    $('#addEntity').change(function(){
            //输出选中项的值
            console.log($(this).val());
            dynamicAddType = $(this).val();
    
            var typeId = $(this).find('option:selected').data('typeid');
            console.log("custom typeid ",typeId)
    
            var resourcename = $(this).find('option:selected').data('resourcename');
            console.log("custom resourcename ",resourcename)
            
          });
  • 相关阅读:
    vue 路由跳转传参
    vue better-scroll 下拉上拉,加载刷新
    H5点击拨打电话,发短信
    vue搭建项目
    How to determine the socket connection up time on Linux
    @ContextConfiguration注解
    MySQL修改主键属性
    软件测试工程师面试(一)
    Python实现不同格式打印九九乘法表
    MySQL 5.1安装和配置过程中遇到的问题
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/15532220.html
Copyright © 2011-2022 走看看