<p>今天看视频学习时学习了一种新技术,即平时我们在一个页面点击&quot;提交&quot;或&quot;确认&quot;会自动跳转到一个页面。</p><p>在网上搜了一下,关于这个技术处理有多种方法,我只记下我在视频里学到的三种:</p><p>1、用一个response.sendRedirect(&quot;目标页面.jsp\.htm&quot;);实现直接跳转;</p><p>2、有时我们需要有点提示,比如&quot;x秒后自动跳转,若没有跳转,请点击此处&quot;,则可以在myeclipse中调用Snippets中的Delay Go To URL.会自动生成如下代码:</p><p>代码如下:</p><pre class="brush:js;toolbar:false">&lt;scriptlanguage=&quot;JavaScript1.2&quot;type=&quot;text/javascript&quot;&gt; &lt;!-- //Placethisinthe&#39;head&#39;sectionofyourpage. functiondelayURL(url,time){ setTimeout(&quot;top.location.href=&#39;&quot;+url+&quot;&#39;&quot;,time); } //--&gt; &lt;/script&gt;</pre><p><br/></p><p>&lt;!-- Place this in the &#39;body&#39; section --&gt;</p><p>&lt;a href=&quot;javascript:&quot; onClick=&quot;delayURL(&#39;myPage.html&#39;,&#39;2000&#39;)&quot;&gt;My Delayed Link&lt;/a&gt;</p><p>将此代码修改为:</p><p>代码如下:</p><pre class="brush:js;toolbar:false">&lt;scriptlanguage=&quot;JavaScript1.2&quot;type=&quot;text/javascript&quot;&gt; functiondelayURL(url,time){ setTimeout(&quot;top.location.href=&#39;&quot;+url+&quot;&#39;&quot;,time); } &lt;/script&gt;</pre><p><br/></p><p>&lt;span id=&quot;time&quot; style=&quot;background: red&quot;&gt;3&lt;/span&gt;</p><p>秒钟之后自动跳转,如果不跳转,请点击下面链接</p><p>&lt;a href=&quot;目标页面.jsp&quot;&gt;目标页面&lt;/a&gt;</p><pre class="brush:js;toolbar:false">&lt;scripttype=&quot;text/javascript&quot;&gt; delayURL(&quot;http://www.hualai.net.cn&quot;,3000); &lt;/script&gt;</pre><p>然后将在3秒钟之后直接跳转到&quot;目标页面&quot;。这种方法就是设定几秒钟后跳转则在这过程中页面不会有变化,比如说设定3秒,然后随着时间的变化3变成2再变成1直至跳转,下面请看第三种方法。</p><p>3、把方法2中的代码修改为:</p><p>代码如下:</p><pre class="brush:js;toolbar:false">&lt;scriptlanguage=&quot;JavaScript1.2&quot;type=&quot;text/javascript&quot;&gt; functiondelayURL(url){ vardelay=document.getElementById(&quot;time&quot;).innerHTML; //最后的innerHTML不能丢,否则delay为一个对象 if(delay&gt;0){ delay--; document.getElementById(&quot;time&quot;).innerHTML=delay; }else{ window.top.location.href=url; } setTimeout(&quot;delayURL(&#39;&quot;+url+&quot;&#39;)&quot;,1000); //此处1000毫秒即每一秒跳转一次 } &lt;/script&gt; &lt;spanid=&quot;time&quot;style=&quot;background:red&quot;&gt;3&lt;/span&gt; 秒钟之后自动跳转,如果不跳转,请点击下面链接 &lt;ahref=&quot;目标页面.jsp&quot;&gt;主题列表&lt;/a&gt; &lt;scripttype=&quot;text/javascript&quot;&gt; delayURL(&quot;http://www.hualai.net.cn/news/knowledge/265.html&quot;); &lt;/script&gt;</pre><p>此方法实现的效果为在上一个页面点击完submit后跳转到本页面经过3秒(这个3会递减到0)后跳转到目标页面</p>
T:0.008170s,M:248.07 KB
返回顶部 留言