0

誰かがこのコードに JavaScript の遅延を入力するのを手伝ってくれますか? このコードを 2 秒後に開くようにします。URLを開くと。サイトの残りの負荷は正常です。

<script type="text/javascript">

var avail=$z:value[article.availableinstock];

if ($z:value[article.availableinstock] < 1)
{
document.write('<div class="shop_not">');
document.write("In order!");
}
else if ($z:value[article.availableinstock] >=100)
{
document.write('<div class="shop_ok">');
document.write(" 100+ in stock" );
}
else if ($z:value[article.availableinstock] >=50 )
{
document.write('<div class="shop_ok">');
document.write(" 50+ in stock" );
}
else if ($z:value[article.availableinstock] >=25 )
{
document.write('<div class="shop_ok">');
document.write(" 25+ in stock" );
}
else
{
document.write('<div class="shop_bob">');
document.write(+ avail.toFixed(0));
document.write(" in stock" );
}
</script>
4

2 に答える 2

1

解決策は、すべてをsetTimeout(function() {... your stuff ...}, 2000)呼び出すことです。

これは次のようになります。

function yourStuff() {
  var avail=$z:value[article.availableinstock];

  if ($z:value[article.availableinstock] < 1) {
    document.write('<div class="shop_not">');
    document.write("In order!");
  } else if ($z:value[article.availableinstock] >=100) {
    document.write('<div class="shop_ok">');
    document.write(" 100+ in stock" );
  } else if ($z:value[article.availableinstock] >=50 ) {
    document.write('<div class="shop_ok">');
    document.write(" 50+ in stock" );
  } else if ($z:value[article.availableinstock] >=25 ) {
    document.write('<div class="shop_ok">');
    document.write(" 25+ in stock" );
  } else {
    document.write('<div class="shop_bob">');
    document.write(+ avail.toFixed(0));
    document.write(" in stock" );
  }
}

次に、ページ内のどこかでbody単に電話します

<script type="text/javascript">setTimeout(yourStuff, 2000);</script>
于 2012-10-12T09:33:12.703 に答える
0

コードを関数で囲み、setTimeoutJS関数を使用します。

function function_name () {
    var avail=$z:value[article.availableinstock];

    if ($z:value[article.availableinstock] < 1)
    {
        document.write('<div class="shop_not">');
        document.write("In order!");
    }
    else if ($z:value[article.availableinstock] >=100)
    {
        document.write('<div class="shop_ok">');
        document.write(" 100+ in stock" );
    }
    else if ($z:value[article.availableinstock] >=50 )
    {
        document.write('<div class="shop_ok">');
        document.write(" 50+ in stock" );
    }
    else if ($z:value[article.availableinstock] >=25 )
    {
        document.write('<div class="shop_ok">');
        document.write(" 25+ in stock" );
    }
    else
    {
        document.write('<div class="shop_bob">');
        document.write(+ avail.toFixed(0));
        document.write(" in stock" );
    }
}

setTimeout('function_name()', 2000);
于 2012-10-12T09:33:11.237 に答える