开发者

Change JS function to jQuery

How can I change this code to take advantage of jQuery?

function download(elm) {
    var iframe = document.createElement("iframe");
    var param = elm.innerHTML; //$get("filedownload").innerHTML;        
    //iframe.src = "GenerateFile.aspx?filename=386c1a94-fa5a-4cfd-b0ae-40995062f70b&ctype=application/octet-stream&ori=18e73bace0ce42119dbbda2d9fe06402.xls";// + param;
    iframe.s开发者_如何学Gorc = "GenerateFile.aspx?" + param;

    iframe.style.display = "none";

    document.body.appendChild(iframe);
}


It would look like this:

function download(elm) {
  $("<iframe />", { src: "GenerateFile.aspx?" + elm.innerHTML })
    .appendTo("body").hide();
}

This is the jQuery 1.4+ $(html, props) syntax, for older versions it would look like this:

function download(elm) {
  $("<iframe />").attr("src","GenerateFile.aspx?" + elm.innerHTML)
    .appendTo("body").hide();
}

Past the creation .appendTo() appends the element you created to the selector passed in ("body"), and .hide() covers the display: none; styling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜