• 项目中常用的JS操作技巧


    1.<a>标签-超链接中confirm方法使用介绍

    <a href="a.html" onclick="if(confirm('确定删除?')==false)return false;">删除</a>

    2.<select>下拉框三级联动效果

    1).html代码

    <select name="select_element" id="firstServiceType"></select>
    <select name="select_element" id="secondServiceType"></select>
    <select name="select_element" id="thirdServiceType"></select>

    2).JS代码

    <script type="text/javascript">

    $(document).ready(function () {
    $("#code").val();
    GetFirstType();
    $("#firstServiceType").change(function () { $("#Type").val($(this).val()); GetSecondType() });
    $("#secondServiceType").change(function () { $("#Type").val($(this).val()); GetThirdType() });
    $("#thirdServiceType").change(function () { $("#Type").val($(this).val()); });
    });
    function GetFirstType() {
    $("#firstServiceType").empty();
    $("#firstServiceType").append('<option>请选择</option>');
    $.getJSON("/ServiceType/GetFirstType", function (data) {
    $.each(data, function (i, item) {
    $("<option></option>")
    .val(item["Code"])
    .text(item["AbbrName"])
    .appendTo($("#firstServiceType"));
    });
    GetSecondType();
    });
    }
    function GetSecondType() {
    $("#secondServiceType").empty();
    $("#secondServiceType").append('<option value="0">请选择</option>');
    var url = "/ServiceType/GetSecondType/?code=" + $("#firstServiceType").val();

    $.getJSON(url, function (data) {

    $.each(data, function (i, item) {
    $("<option></option>")
    .val(item["Code"])
    .text(item["AbbrName"])
    .appendTo($("#secondServiceType"));
    });
    GetThirdType();
    });
    }
    function GetThirdType() {
    $("#thirdServiceType").empty();
    $("#thirdServiceType").append('<option value="0">请选择</option>');
    var url = "/ServiceType/GetThirdType/?code=" + $("#secondServiceType").val();
    $.getJSON(url, function (data) {
    $.each(data, function (i, item) {
    $("<option></option>")
    .val(item["Code"])
    .text(item["AbbrName"])
    .appendTo($("#thirdServiceType"));
    });

    });
    }
    </script>

    3.上传图片时预览功能

    1).htm代码

    <img id="img" style="100px; height:100px;" src=""/>

    <input type="file" name="pic" id="file" />

    2).JS代码

    <script type="text/javascript">
    $(document).ready(function () {
    $("#file").bind("change", function () {
    var f = document.getElementById('file').files[0];
    var src = window.URL.createObjectURL(f);
    $("#img").attr("src", src);

    })

    });
    </script>

  • 相关阅读:
    C++ std::forward_list
    MyBatis基础入门《十三》批量新增数据
    MyBatis基础入门《十二》删除数据
    MyBatis基础入门《十 一》修改数据
    MyBatis基础入门《十》添加数据
    MyBatis基础入门《九》ResultMap自动匹配
    MyBatis基础入门《八》查询参数传入Map
    MyBatis基础入门《七》查询参数传入对象
    MyBatis基础入门《六》Like模糊查询
    MyBatis基础入门《五》核心配置文件
  • 原文地址:https://www.cnblogs.com/CeleryCabbage/p/4705028.html
Copyright © 2020-2023  润新知