最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)圖片上傳與瀏覽切換的方法

 更新時(shí)間:2014年08月25日 11:09:09   投稿:shichen2014  
這篇文章主要介紹了C#實(shí)現(xiàn)圖片上傳與瀏覽切換的方法,是很有實(shí)用價(jià)值的一個(gè)應(yīng)用技巧,需要的朋友可以參考下

本文以一個(gè)完整實(shí)例講述了C#實(shí)現(xiàn)圖片上傳與瀏覽切換的方法,對(duì)于進(jìn)行C#程序設(shè)計(jì)來(lái)說(shuō)具有一定的借鑒價(jià)值。分享給大家供大家參考。

具體實(shí)現(xiàn)代碼如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>無(wú)標(biāo)題頁(yè)</title>
  <script src="js/jquery-1.7.2.js" type="text/javascript"></script>
  <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $('.upic').change(function() {
        var filename = $(this).val().replace(/.*(\/|\\)/, ""); //文件名
        var fileExt = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : ''; //后綴名
        if (fileExt != "jpeg" && fileExt != "jpg" && fileExt != "gif" && fileExt != "png") {
          alert('請(qǐng)選擇一個(gè)jpg或gif的圖片文件');
          return;
        };
        $(this).parent().parent().parent().addClass('support');
        if ($.browser.msie) {
          if ($.browser.version == "6.0") {
            $(this).parent().parent().siblings(".preview").html('<img style="height:auto;width:88px;" src="' + $(this).val() + '"/>');
          } else {
            var previewDiv = $(this).parent().parent().siblings(".preview");
            previewDiv.css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image)" });
            previewDiv[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale";
            try {
              previewDiv[0].filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = getPath($(this)[0]);
            }
            catch (e) {
              alert(e.name + ": " + e.message);
              alert("無(wú)效的圖片文件!");
              return;
            }
          }
        }
        else {
          //var data=$(this)[0].files.item(0).getAsDataURL();
          var data = window.URL.createObjectURL($(this)[0].files[0]);
          $(this).parent().parent().siblings(".preview").html('<img style="height:auto;width:88px;" src="' + data + '"/>');
          return;
        }
        $(this).parent().parent().parent().mouseover(function() { $(this).addClass('hover'); }).mouseout(function() { $(this).removeClass('hover'); });
      });
      $('.del').click(function() {
        $(this).parent().siblings("[name='isDel']").val("1");
        var file = $(this).parent().siblings(".upload").children().children(".upic");
        file.after(file.clone(true).val("")).remove();
        $(this).parent().siblings(".preview").after('<div class="preview"></div>').remove();
        //$(this).parent().siblings(".preview").empty();
        $(this).parent().parent().removeClass('support').mouseout().unbind('mouseover');
      });
      if ($.browser.msie) {
        $('#memberPhoto').filter('.support').mouseover(function() { $(this).addClass('hover'); }).mouseout(function() { $(this).removeClass('hover'); });
      };
      //獲得上傳控件的值,obj為上傳控件對(duì)象
      function getPath(obj) {
        if (obj) {
          if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
            obj.select();
            document.getElementById("btnSave").focus(); //hack for IE9下,如果file控件獲得焦點(diǎn),則document.selection.createRange()拒絕訪問(wèn)
            return document.selection.createRange().text;
          }
          else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
            if (obj.files) {
              return obj.files.item(0).getAsDataURL();
            }
            return obj.value;
          }
          return obj.value;
        }
      }
    });
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div id="pic">
    <div id="memberPhoto" style="position: relative">
      <%if (!string.IsNullOrEmpty(imagePath))
       {%>
      <div class="preview">
        <img src="../<%=imagePath%>" style="height: auto; width: 88px;" /></div>
      <%}
       else
       {%>
      <div class="preview">
      </div>
      <%}%>
      <div class="upload">
        <a class="a-sc" href="javascript:;">
          <input id="imageUpload" class="upic" type="file" name="upic" runat="server" />
        </a>
      </div>
      <div class="act">
        <span class="del">刪除</span>
      </div>
    </div>
  </div>
  </form>
</body>
</html>

public partial class Default3 : System.Web.UI.Page
{
  public string imagePath = "";
  protected void Page_Load(object sender, EventArgs e)
  {

  }
}

希望本文實(shí)例對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • c# 判斷是否為空然后賦值的4種實(shí)現(xiàn)方法

    c# 判斷是否為空然后賦值的4種實(shí)現(xiàn)方法

    下面小編就為大家分享一篇c# 判斷是否為空然后賦值的4種實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • 算法證明每一位都相同十進(jìn)制數(shù)不是完全平方數(shù)

    算法證明每一位都相同十進(jìn)制數(shù)不是完全平方數(shù)

    這篇文章主要為大家介紹了算法證明每一位都相同十進(jìn)制數(shù)不是完全平方數(shù)的過(guò)程論述,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • C#中的并發(fā)集合Concurrent類

    C#中的并發(fā)集合Concurrent類

    這篇文章介紹了C#中的并發(fā)集合Concurrent類,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • Unity2D實(shí)現(xiàn)游戲回旋鏢

    Unity2D實(shí)現(xiàn)游戲回旋鏢

    這篇文章主要為大家詳細(xì)介紹了Unity2D實(shí)現(xiàn)游戲回旋鏢,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Unity3D基于OnGUI實(shí)時(shí)顯示FPS

    Unity3D基于OnGUI實(shí)時(shí)顯示FPS

    這篇文章主要介紹了Unity3D基于OnGUI實(shí)時(shí)顯示FPS,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • DataGridView控件常用屬性介紹

    DataGridView控件常用屬性介紹

    這篇文章介紹了DataGridView控件的常用屬性,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-02-02
  • C#通過(guò)html調(diào)用WinForm的方法

    C#通過(guò)html調(diào)用WinForm的方法

    這篇文章主要介紹了C#通過(guò)html調(diào)用WinForm的方法,涉及html頁(yè)面中使用JavaScript訪問(wèn)C#的相關(guān)技巧,需要的朋友可以參考下
    2016-04-04
  • C#中的屬性解析(get、set、value)

    C#中的屬性解析(get、set、value)

    這篇文章主要介紹了C#中的屬性(get、set、value),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • C#實(shí)現(xiàn)DataTable轉(zhuǎn)換成IList的方法

    C#實(shí)現(xiàn)DataTable轉(zhuǎn)換成IList的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)DataTable轉(zhuǎn)換成IList的方法,涉及C#針對(duì)DataTable操作的相關(guān)技巧,需要的朋友可以參考下
    2016-03-03
  • C#定制Excel界面并實(shí)現(xiàn)與數(shù)據(jù)庫(kù)交互的方法

    C#定制Excel界面并實(shí)現(xiàn)與數(shù)據(jù)庫(kù)交互的方法

    這篇文章主要介紹了C#定制Excel界面并實(shí)現(xiàn)與數(shù)據(jù)庫(kù)交互的方法的相關(guān)資料,需要的朋友可以參考下
    2015-11-11

最新評(píng)論

银川市| 长武县| 宁明县| 友谊县| 遵义县| 光山县| 二连浩特市| 镇原县| 平凉市| 扶风县| 开封县| 博野县| 海原县| 弥勒县| SHOW| 微博| 永清县| 崇信县| 信阳市| 平潭县| 永年县| 宜良县| 义乌市| 阜新| 绵竹市| 莆田市| 漠河县| 宣威市| 余姚市| 张掖市| 昭通市| 顺昌县| 贞丰县| 乌拉特后旗| 鄂尔多斯市| 易门县| 维西| 海门市| 黄冈市| 聂荣县| 象山县|