Js 中常用方法

來源:互聯網
上載者:User

標籤:

一、擷取唯一值(2014-12-23)

1 function newGuid() {2     var guid = "";3     var n = (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);4     for (var i = 1; i <= 8; i++) {5         guid += n;6     }7     return guid;8 }
View Code

二、ajaxfileupload.js(下載js外掛程式)使用

$("#bttUp").click(function () {    var value_temp = $("#fileUp").val();    if (value_temp != "" && value_temp != null && value_temp != undefined && value_temp.length > 0) {        var id = newGuid();        var url_ = "";        $.ajaxFileUpload({            url: "../../Handler/ManagerHandler.ashx",            type: "POST",            fileElementId: "fileUp",            dataType: "text/plain",            data: { oprate: "upimg", type: $("#ddlImgType option:selected").val() },            beforeSend: function () {                alert("beforeSend");            },            complete: function () {                copyToClipboard(id, url_);            },            success: function (data, status) {                url_ = $(data).text();                var img = "<img src = \"" + url_ + "\"/>";                $("#tbUrlList").prepend("<tr><td >" + img + "</td><td><input type=‘text‘ readonly=‘readonly‘ value=‘" + url_ + "‘/></td><td><input value=‘複製地址‘ type=‘button‘ id=‘" + id + "‘ class=‘copyurl‘ name=‘" + url_ + "‘/></td></tr>");            },            error: function (data, status, e) {                alert("error");            }        })    }});
View Code

三、ZeroClipboard.js(flash下載粘貼)使用

 1 //id : button控制項id ,txt:要複製的內容 2 function copyToClipboard(id, txt) { 3     var clip = new ZeroClipboard.Client(); 4     clip.setHandCursor(true); 5     clip.setText(txt); 6     clip.glue(id); 7     clip.addEventListener("complete", function () { 8         alert("複製成功!"); 9     });10 }
View Code

注意:傳入的id必須唯一,如重複,則覆蓋。

Js 中常用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.