• 为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)
            
          });
  • 相关阅读:
    表的外键创建:
    django内容回顾:
    编辑出版社:
    删除出版社:
    新增出版社:
    Windows XP SP3中远程桌面实现多用户登陆
    Hibernate基本概念 (4)
    Hibernate基本概念 (3)
    Hibernate基本概念 (3)
    Hibernate基本概念 (3)
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/15532220.html
Copyright © 2020-2023  润新知