繁体   English   中英

在标记中调用 Javascript function 时遇到问题

[英]Trouble calling Javascript function within markup

我无法让我的 Javascript 运行。

我的 javascript 位于我的主文件的正文标记内(布局页面)

<script type="text/javascript">

   var cssdropdown = {
        startchrome2: function() {
             document.getElementById("P3").innerHTML = "3 is complete"; 
        }
   }

</script>

我试图调用 startchrome2 function 如下:

<body onload="cssDropDown.startchrome2()">

我在 getElementById 调用中尝试访问的元素也位于正文中:

<p id="P3">This is a paragraph.</p>

它当前显示“这是一个段落”。 为什么我的 javascript 无法将其更改为“3 已完成”?

我一直在玩弄这个,这很令人沮丧。 我确定这是一个愚蠢的错误。

我在 Visual Studio 2010 中工作,以下是页面顶部的声明:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs"
    Inherits="SiteMaster" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"  
    TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

您的外壳错误,请尝试:

<body onload="cssdropdown.startchrome2()">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM