Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

javascript - 事件未触发(onclick)(Event not firing up (onclick))

Try changing almost everything(ie runat="server", single-double colons) Here is the try:

(尝试更改几乎所有内容(即runat =“ server”,单双冒号),这是尝试的方法:)

<head runat="server">

<script type="text/javascript" >

    function Decide() {

        document.getElementById('l').innerText = "after";

    }

</script>
</head>

<body>
    <form id="form1" runat="server">
        <button    onclick="Decide()">Click!</button>
        <asp:Label ID="l" runat="server">before</asp:Label>

    </form>
</body>

What am I doing wrong?

(我究竟做错了什么?)

  ask by Jamil translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check the generated html (source code) to check if the generated for label has the same Id.

(检查生成的html(源代码)以检查生成的for标签是否具有相同的ID。)

The Id for the label is the server side Id, not client side.

(标签的ID是服务器端ID,而不是客户端。)

That's the reason why the javascript does not find the element.

(这就是javascript无法找到该元素的原因。)

Add the ClientId property to your label control (ClientId="l") and check again.

(将ClientId属性添加到标签控件(ClientId =“ l”),然后再次检查。)

Greetings

(问候)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...