第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何讓放在body前面的js代碼運(yùn)行

如何讓放在body前面的js代碼運(yùn)行

心寧安心 2016-06-03 16:03:17
下面的代碼,js是放在body的底部的,我想放在</style>的下面,也就是body前面運(yùn)行,但是顯示結(jié)果是失敗的,要怎么修改,才能放在頂部,或者放在單獨(dú)的js文件中,謝謝!<!Doctype html><html>?? ?<head>?? ??? ?<meta charset="utf-8" />?? ??? ?<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />?? ??? ?<title>調(diào)試</title>?? ??? ?<style>?? ??? ??? ?*{margin:0; padding:0; color:black;}?? ??? ??? ?ul{list-style:none;}?? ??? ??? ?a{text-decoration:none;}?? ??? ??? ?a:hover{color:orange;}?? ??? ??? ?#articleList{width:400px; border:5px solid gray;}?? ??? ??? ?#articleTitle{height:50px; line-height:50px; font-size:24px; text-align:center; border-bottom:1px solid gray;}?? ??? ??? ?#articleContent{width:350px; height:125px; margin:10px 25px; overflow:hidden;}?? ??? ??? ?#articleContent ul li a{width:200px; height:25px; line-height:25px; display:inline-block; padding-left:15px; overflow:hidden;}?? ??? ??? ?#articleContent ul li span{float:right; color:gray;}?? ??? ?</style>?? ?</head>?? ?<body>?? ??? ?<div id="articleList">?? ??? ??? ?<h3 id="articleTitle">最近更新文章</h3>?? ??? ??? ?<div id="articleContent">?? ??? ??? ??? ?<ul id="newList">?? ??? ??? ??? ??? ?<li><a href="#">1.做對(duì)自己有意義的事</a><span>2016-05-28</span></li>?? ??? ??? ???????? <li><a href="#">2.關(guān)于CSS選擇器繼承</a><span>2016-05-30</span></li>?? ??? ??? ???????? <li><a href="#">3.自己動(dòng)手,豐衣足食</a><span>2016-06-01</span></li>?? ??? ??? ???????? <li><a href="#">4.論inline-block</a><span>2016-06-02</span></li>?? ??? ??? ???????? <li><a href="#">5.更多正在編寫(xiě)中……</a><span>2016-06-02</span></li>?? ??? ??? ??? ?</ul>?? ??? ??? ??? ?<ul id="newListTemp"></ul>?? ??? ??? ?</div>?? ??? ?</div>?? ???? <script>?? ??? ??? ?var area = document.getElementById("articleContent");?? ??? ??? ?var newList = document.getElementById("newList");?? ??? ??? ?var newListTemp = document.getElementById("newListTemp");?? ??? ??? ?var speed = 50;?? ??? ??? ?area.scrollTop = 0;?? ??? ??? ?newListTemp.innerHTML = newList.innerHTML;?? ??? ??? ??? ??? ??? ?function scrollUp(){?? ??? ??? ??? ?if(area.scrollTop >= newList.scrollHeight){?? ??? ??? ??? ??? ?area.scrollTop = 0;?? ??? ??? ??? ?}?? ??? ??? ??? ?else{?? ??? ??? ??? ??? ?area.scrollTop ++;?? ??? ??? ??? ?}?? ??? ??? ?}?? ??? ??? ?var myScroll = setInterval("scrollUp()", speed);?? ??? ??? ?area.onmouseover = function(){?? ??? ??? ??? ?clearInterval(myScroll);?? ??? ??? ?}?? ??? ??? ?area.onmouseout = function(){?? ??? ??? ??? ?myScroll = setInterval("scrollUp()", speed);?? ??? ??? ?}?? ??? ?</script>?? ?</body></html>
查看完整描述

2 回答

已采納
?
LHammer

TA貢獻(xiàn)9條經(jīng)驗(yàn) 獲得超3個(gè)贊

再試試

<!Doctype html>

<html>

? ? <head>

? ? ? ? <meta charset="utf-8" />

? ? ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />

? ? ? ? <title>調(diào)試</title>

? ? ? ? <style>

? ? ? ? ? ? *{margin:0; padding:0; color:black;}

? ? ? ? ? ? ul{list-style:none;}

? ? ? ? ? ? a{text-decoration:none;}

? ? ? ? ? ? a:hover{color:orange;}

? ? ? ? ? ? #articleList{width:400px; border:5px solid gray;}

? ? ? ? ? ? #articleTitle{height:50px; line-height:50px; font-size:24px; text-align:center; border-bottom:1px solid gray;}

? ? ? ? ? ? #articleContent{width:350px; height:125px; margin:10px 25px; overflow:hidden;}

? ? ? ? ? ? #articleContent ul li a{width:200px; height:25px; line-height:25px; display:inline-block; padding-left:15px; overflow:hidden;}

? ? ? ? ? ? #articleContent ul li span{float:right; color:gray;}

? ? ? ? </style>

? ? ? ? <script>

? ? ? ? ? ? window.onload = function(){

? ? ? ? ? ? ? ? var area = document.getElementById("articleContent");

? ? ? ? ? ? ? ? var newList = document.getElementById("newList");

? ? ? ? ? ? ? ? var newListTemp = document.getElementById("newListTemp");

? ? ? ? ? ? ? ? var speed = 50;

? ? ? ? ? ? ? ? area.scrollTop = 0;

? ? ? ? ? ? ? ? newListTemp.innerHTML = newList.innerHTML;

? ? ? ? ? ? ? ? var myScroll = setInterval(scrollUp, speed);

? ? ? ? ? ? ? ? area.onmouseover = function(){

? ? ? ? ? ? ? ? ? ? clearInterval(myScroll);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? area.onmouseout = function(){

? ? ? ? ? ? ? ? ? ? myScroll = setInterval(scrollUp, speed);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? function scrollUp(){

? ? ? ? ? ? ? ? ? ? if(area.scrollTop >= newList.scrollHeight){

? ? ? ? ? ? ? ? ? ? ? ? area.scrollTop = 0;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? else{

? ? ? ? ? ? ? ? ? ? ? ? area.scrollTop ++;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }?

? ? ? ? ? ? }

? ? ? ? </script>?

? ? </head>

? ? <body>

? ? ? ? <div id="articleList">

? ? ? ? ? ? <h3 id="articleTitle">最近更新文章</h3>

? ? ? ? ? ? <div id="articleContent">

? ? ? ? ? ? ? ? <ul id="newList">

? ? ? ? ? ? ? ? ? ? <li><a href="#">1.做對(duì)自己有意義的事</a><span>2016-05-28</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">2.關(guān)于CSS選擇器繼承</a><span>2016-05-30</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">3.自己動(dòng)手,豐衣足食</a><span>2016-06-01</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">4.論inline-block</a><span>2016-06-02</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">5.更多正在編寫(xiě)中……</a><span>2016-06-02</span></li>

? ? ? ? ? ? ? ? </ul>

? ? ? ? ? ? ? ? <ul id="newListTemp"></ul>

? ? ? ? ? ? </div>

? ? ? ? </div>

? ? </body>

</html>


查看完整回答
反對(duì) 回復(fù) 2016-06-06
?
LHammer

TA貢獻(xiàn)9條經(jīng)驗(yàn) 獲得超3個(gè)贊

js中可以用window onload() ?代表頁(yè)面全部加載完成之后在執(zhí)行之下的代碼

<!Doctype html>

<html>

? ? <head>

? ? ? ? <meta charset="utf-8" />

? ? ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />

? ? ? ? <title>調(diào)試</title>

? ? ? ? <style>

? ? ? ? ? ? *{margin:0; padding:0; color:black;}

? ? ? ? ? ? ul{list-style:none;}

? ? ? ? ? ? a{text-decoration:none;}

? ? ? ? ? ? a:hover{color:orange;}

? ? ? ? ? ? #articleList{width:400px; border:5px solid gray;}

? ? ? ? ? ? #articleTitle{height:50px; line-height:50px; font-size:24px; text-align:center; border-bottom:1px solid gray;}

? ? ? ? ? ? #articleContent{width:350px; height:125px; margin:10px 25px; overflow:hidden;}

? ? ? ? ? ? #articleContent ul li a{width:200px; height:25px; line-height:25px; display:inline-block; padding-left:15px; overflow:hidden;}

? ? ? ? ? ? #articleContent ul li span{float:right; color:gray;}

? ? ? ? </style>

? ? ? ? ?<script>

? ? ? ? ?window.onload = function(){

? ? ? ? ? var area = document.getElementById("articleContent");

? ? ? ? ? ? var newList = document.getElementById("newList");

? ? ? ? ? ? var newListTemp = document.getElementById("newListTemp");

? ? ? ? ? ? var speed = 50;

? ? ? ? ? ? area.scrollTop = 0;

? ? ? ? ? ? newListTemp.innerHTML = newList.innerHTML;

? ? ? ? ? ??

? ? ? ? ? ? function scrollUp(){

? ? ? ? ? ? ? ? if(area.scrollTop >= newList.scrollHeight){

? ? ? ? ? ? ? ? ? ? area.scrollTop = 0;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? else{

? ? ? ? ? ? ? ? ? ? area.scrollTop ++;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? var myScroll = setInterval("scrollUp()", speed);

? ? ? ? ? ? area.onmouseover = function(){

? ? ? ? ? ? ? ? clearInterval(myScroll);

? ? ? ? ? ? }

? ? ? ? ? ? area.onmouseout = function(){

? ? ? ? ? ? ? ? myScroll = setInterval("scrollUp()", speed);

? ? ? ? ? ? }

? ? ? ? } ?

? ? ? ? </script>

? ? </head>

? ? <body>

? ? ? ? <div id="articleList">

? ? ? ? ? ? <h3 id="articleTitle">最近更新文章</h3>

? ? ? ? ? ? <div id="articleContent">

? ? ? ? ? ? ? ? <ul id="newList">

? ? ? ? ? ? ? ? ? ? <li><a href="#">1.做對(duì)自己有意義的事</a><span>2016-05-28</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">2.關(guān)于CSS選擇器繼承</a><span>2016-05-30</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">3.自己動(dòng)手,豐衣足食</a><span>2016-06-01</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">4.論inline-block</a><span>2016-06-02</span></li>

? ? ? ? ? ? ? ? ? ? <li><a href="#">5.更多正在編寫(xiě)中……</a><span>2016-06-02</span></li>

? ? ? ? ? ? ? ? </ul>

? ? ? ? ? ? ? ? <ul id="newListTemp"></ul>

? ? ? ? ? ? </div>

? ? ? ? </div>

? ? </body>

</html>


查看完整回答
反對(duì) 回復(fù) 2016-06-03
  • 心寧安心
    心寧安心
    你運(yùn)行過(guò)行了?我剛才又試了一遍,表示不行,這個(gè)我一開(kāi)始想過(guò),也試過(guò),能不能試成功了再回我,大神0.0
  • 心寧安心
    心寧安心
    錯(cuò)誤碼: Uncaught ReferenceError: scrollUp is not defined 5 Uncaught ReferenceError: scrollUp is not defined(anonymous function) @ VM52:1 1662 console messages are not shown. 604 Uncaught ReferenceError: scrollUp is not defined
  • LHammer
    LHammer
    兄弟呀~ 我看你寫(xiě)的題目還以為你放在body后是可以順利運(yùn)行的~ 下次把題目寫(xiě)明白咯~ 你的問(wèn)題出在定時(shí)器setInterval中,正確的格式setInterval(code,millisec) 第一個(gè)參數(shù)為函數(shù)代碼(如果調(diào)用函數(shù)直接寫(xiě)函數(shù)名即可 不要加引號(hào) ),第二個(gè)參數(shù)為時(shí)間間隔
  • 2 回答
  • 1 關(guān)注
  • 3101 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)