我試圖在我們網站的主頁上粘貼新聞滾動條。我收到「Object Required」錯誤消息
我有點被我得到,因爲我明白了一臺電腦上,但沒有其他錯誤信息混淆:
必選對象
我使用下面的代碼,但以下行不斷拋出Object Required
錯誤,當我使用這個文件作爲web用戶控件在我default.aspx page
:
el2.style.height='<%=box_height %>';
作爲結果,新聞不滾動。
任何幫助極大的讚賞。
<a href="#"><uc1:NewsScroller ID="NewsScroller1" runat="server" /></a>
<script language="VB" runat="server">
Public box_TextColor As String = "black"
Public box_height As Integer = 150
Public box_width As Integer = 166
Public box_padding As String = "0 0 0 20"
</script>
<script type="text/javascript" for="window" event="onload">
// <!CDATA[
return window_onload()
// ]]>
</script>
<script type="text/javascript">
// <!CDATA[
// <!--
var speed = 2;
function init(){
var el = document.getElementById("newsdiv");
el.style.overflow = 'hidden';
el.style.height='<%=box_height %>';
el.style.width='<%=box_width %>';
el.style.padding='<%=box_padding %>';
el.style.color='<%=box_TextColor %>';
var el2 = document.getElementById("newsdiv-p1");
el2.style.height='<%=box_height %>';
var el3 = document.getElementById("newsdiv-p2");
el3.style.height='<%=box_height %>';
//alert(document.getElementById("newsdiv-p2").style.height+document.getElementById("newsdiv-p2").style.height);
scrollFromBottom();
}
var go = 0;
var timeout = '';
function scrollFromBottom(){
clearTimeout(timeout);
var el = document.getElementById("newsdiv");
if(el.scrollTop >= el.scrollHeight-'<%=box_height %>'){
el.scrollTop = 0;
};
el.scrollTop = el.scrollTop + speed;
if(go == 0){
timeout = setTimeout("scrollFromBottom()",50);
};
}
function stop(){
go = 1;
}
function startit(){
go = 0;
scrollFromBottom();
}
// -->
function window_onload() {
init();
}
// ]]>
</script>
<%--<asp:Panel ID="newsdiv" runat="server" onmouseout="startit();" onmouseover="stop();">--%>
<div id="newsdiv" onmouseout="startit();" onmouseover="stop();" >
<p id="newsdiv-p1" class="spacer"></p>
<asp:Label ID="lblNews" runat="server" Text="News..."></asp:Label>
<p id="newsdiv-p2" class="spacer"></p>
</div>
<%--</asp:Panel>--%>
@Marcel,我想你的意思是源代碼(右鍵單擊,查看源代碼並複製代碼)?
如果是這樣,這是又一次,感謝
<script type="text/javascript" for="window" event="onload">
// <!CDATA[
return window_onload()
// ]]>
</script>
<script type="text/javascript">
// <!CDATA[
// <!--
var speed = 2;
$(document).ready(function init(){
var el = document.getElementById("newsdiv");
el.style.overflow = 'hidden';
el.style.height='150';
el.style.width='166';
el.style.padding='0 0 0 20';
el.style.color='black';
var el2 = document.getElementById("newsdiv-p1");
el2.style.height='150';
var el3 = document.getElementById("newsdiv-p2");
el3.style.height='150';
//alert(document.getElementById("newsdiv-p2").style.height+document.getElementById("newsdiv-p2").style.height);
scrollFromBottom();
});
var go = 0;
var timeout = '';
function scrollFromBottom(){
clearTimeout(timeout);
var el = document.getElementById("newsdiv");
if(el.scrollTop >= el.scrollHeight-'150'){
el.scrollTop = 0;
};
el.scrollTop = el.scrollTop + speed;
if(go == 0){
timeout = setTimeout("scrollFromBottom()",60);
};
}
function stop(){
go = 1;
}
function startit(){
go = 0;
scrollFromBottom();
}
// -->
function window_onload() {
init();
}
// ]]>
</script>
<div id="newsdiv" onmouseout="startit();" onmouseover="stop();" >
<p id="newsdiv-p1" class="spacer">
</p>
<span id="NewsScroller1_lblNews"><a href='#' OnClick=javascript:window.open('newsDetail.aspx?NewsID=10','NewsDetail','width=800,height=600;toolbar=no;');><font face='verdana' size='2' color='#184D68'>Steve's Birthday</font><br><br><a href='#' OnClick=javascript:window.open('newsDetail.aspx?NewsID=15','NewsDetail','width=800,height=600;toolbar=no;');><font face='verdana' size='2' color='#184D68'>Our Anniversary</font><br><br><a href='#' OnClick=javascript:window.open('newsDetail.aspx?NewsID=14','NewsDetail','width=800,height=600;toolbar=no;');><font face='verdana' size='2' color='#184D68'>Jessie's Birthday</font><br><br></span>
<p id="newsdiv-p2" class="spacer"></p>
</div>
我仍然在試圖總結我的頭在這個偉大的論壇是如何工作的。昨天,我能夠看到一個按鈕,上面寫着「添加評論」。從今天起,我一直無法看到它。我想我的問題是,你如何重新登錄,以便你能夠添加評論等?登錄似乎是由cookie驅動的,這意味着一旦關閉瀏覽器,您的權限就會消失,不是嗎?
由於不同的JS引擎,錯誤等,所有這一切發生在不同的瀏覽器中。 – 2011-04-18 13:46:36
@Tomas:這是一個*非常*般的評論,你可以放在關於web開發的幾乎所有問題之下,不,這不是麻煩的原因。這個案例。 – 2011-04-18 14:00:02
您可以顯示HTML發送到瀏覽器時的樣子嗎?我不能'讀'ASP.net並擔心那部分'asp:Panel ID =「newsdiv」...會干擾你的#newsdiv(ID不僅區分大小寫,而且必須是唯一的)。順便說一句,'setTimeout(「scrollFromBottom()」,50)'不是**如何使用'setTimeout',不要向它提供字符串,它有和使用'eval'一樣的陷阱。在這種情況下,只需使用'setTimeout(scrollFromBottom,50)'。 – 2011-04-19 10:49:19