怎么把这段js代码转换成jquery代码

function alertSet(e) {
    document.getElementById("js-alert-box").style.display = "block",
    document.getElementById("js-alert-head").innerHTML = e;
    var t = 20,
    n = document.getElementById("js-sec-circle");
    document.getElementById("js-sec-text").innerHTML = t,
    setInterval(function() {
        if (0 == t){
            location.href="http://www.jq-school.com";
        }else {
            t -= 1,
            document.getElementById("js-sec-text").innerHTML = t;
            var e = Math.round(t / 20 * 735);
            n.style.strokeDashoffset = e - 735
        }
    },
    970);
}
阅读 3.7k
4 个回答
function alertSet(e){
  $("#js-alert-box").css("display","block");
  $("#js-alert-head").html(e);
  var t = 20;
  var $n = $("#js-sec-circle");
  setInterval(function(){
    if(t == 0){
      location.href = "http://www.jq-school.com";
    }else{
      t -= 1,
      $("#js-sec-text").html(t);
      var e = Math.round(t / 20 * 735);
      $n.css("strokeDashoffset",e - 735); 
    }
  },970)
}

不考虑你代码的任何逻辑,对错:

function alertSet(e) {
        $("#js-alert-box").show();
        $("#js-alert-head").html(e);
        var t = 20, n = $("#js-sec-circle");
        $("#js-sec-text").html(t);
        setInterval(function () {
            if (0 === t) {
                location.href = "http://www.jq-school.com";
            } else {
                t -= 1;
                $("#js-sec-text").html(t);
                n.css('stroke-dashoffset', Math.round(t / 20 * 735) - 735);
            }
        },
        970);
    }

顺便说一线,js可以省略结束的分好,但是结束不是逗号。

function alertSet(e) {
    $("#js-alert-box").show(),
    $("#js-alert-head").html(e);
    var t = 20,
    n = $("#js-sec-circle");
    $("#js-sec-text").html(t),
    setInterval(function() {
        if (0 == t){
            location.href="http://www.jq-school.com";
        }else {
            t -= 1,
            $("#js-sec-text").html(t);
            var e = Math.round(t / 20 * 735);
            n.css({strokeDashoffset: e - 735})
        }
    },
    970);
}

这是我的想法,希望能对你有所帮助:

function alertSet(e) {
        $("#js-alert-box").show();
        $("#js-alert-head").html(e);
        var t = 20, $n = $("#js-sec-circle");
        $("#js-sec-text").html(t);
        setInterval(function () {
            if (0 === t) {
                window.location.href = "http://www.jq-school.com";
            } else {
                t -= 1;
                $("#js-sec-text").html(t);
                $n.css('stroke-dashoffset', Math.round(t / 20 * 735) - 735);
            }
        },
        970);
    }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题