为什么JavaScript不在此处填充文本框?

时间:2019-12-13 10:49:39

标签: javascript asp.net

我在Google上搜索了很多,仍然必须缺少一些内容。该方法可以很好地创建弹出对话框,但是当我按下按钮时不会填充文本框。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Proj1.Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ButtonSubmit() {
            var isPressed = document.getElementById('SubmitPressed');
            isPressed.Value = "True";
            alert('You have submitted your request. ');           
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="SubmitPressed" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ButtonSubmit();"/>
        </div>
    </form>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ButtonSubmit() {
            var isPressed = document.getElementById('SubmitPressed');
            isPressed.value = "True";
            alert('You have submitted your request. ');
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="SubmitPressed" ClientIDMode="Predictable" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ButtonSubmit();"/>
    </div>
    </form>
</body>
</html>

尝试使用上述代码代替现有的文本框

答案 1 :(得分:0)

我需要将.Value更改为.value,因为根据@VDWWD的注释,JavaScript区分大小写。

var isPressed = document.getElementById('SubmitPressed');
isPressed.value = "True";
相关问题