gpt4 book ai didi

c# - 无法从标签获取 javascript 值

转载 作者:行者123 更新时间:2023-11-29 10:20:28 24 4
gpt4 key购买 nike

我是编程新手,请见谅。

我有一个 .js 游戏输出一个名为“score”的变量。

我要求变量能够显示在我的 asp 标签上,然后在 onClick() 上获取它的值用于数据库存储

目前我能做的是:

@.js:

    document.getElementById('score').value = score;

@.aspx:

    <asp:Label runat="server"  ID="score"></asp:Label>

分数现在反射(reflect)在这个标签上。但是,我需要做一个额外的功能,即从标签中获取 'score' 的值并将其用作 C# 中的字符串

最佳答案

使用服务器控件的 ClientID,因为 id 分数会在 asp 生成的 html 中发生变化。

改变

document.getElementById('score').value = score;

document.getElementById('<%= score.ClientID %>').value = score;

关于c# - 无法从标签获取 javascript 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com