在Pageload上调用jScript [英] call jScript on Pageload
本文介绍了在Pageload上调用jScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我第一次在jscript文件中编写任何内容,因此,我需要帮助
这是我在jscript中编写的函数
this is my first time to write anything in jscript file, so please i need help
this is the function i wrote in jscript
function SelectPage(DocURL) {
var ID = document.URL;
switch (DocURL) {
case "Who We Are.aspx":
document.getElementById("Td1").className = "itemHovered";
break;
case "Services.aspx":
document.write("Super Saturday");
break;
case "Products.aspx":
document.write("Sleepy Sunday");
break;
case "Clients.aspx":
document.write("Sleepy Sunday");
break;
case "ContactUs.aspx":
document.write("Sleepy Sunday");
break;
default:
document.write("I'm looking forward to this weekend!");
}
我想在页面加载时称呼这种乐趣
我该怎么做
预先感谢
i want to call this fun on pageload
how can i do that
thankx in advance
推荐答案
如果您想在aspx中从CodeBehind调用JS,则必须使用"Pagemethods". />
http://www.google.com/search?gcx= w& sourceid = chrome& ie = UTF-8& q = pagemethods [
You''ll have to use ''Pagemethods'' if you wanna call JS from CodeBehind in an aspx.. more info here:
http://www.google.com/search?gcx=w&sourceid=chrome&ie=UTF-8&q=pagemethods[^]
if you just want this code to run after page is ready, use Jquery and type
(document).ready(function() { //your code here });
(document).ready(function() { //your code here });
有几种方法.您可以使用
There are several ways. You can use
Page.ClientScript.RegisterStartupScript(this.GetType(), "AnyThing", "SelectPage();", true);
或在aspx一侧,您可以在body标签上使用onload方法.
or in your aspx side you can use the onload method on the body tag.
<body onload="SelectPage();"></body>
或者甚至可以使用jQuery的document.ready()函数
Or you can even use jQuery''s document.ready() function
这篇关于在Pageload上调用jScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文