简体   繁体   English

Razor 页面内的 Razor 组件内的 HTML 按钮

[英]HTML button inside a Razor component within a Razor page

I have a page called CreateForm On my CreateForm page, after the customer enters the data, they can preview their entry before I save it to the database.我有一个名为 CreateForm 的页面 在我的 CreateForm 页面上,客户输入数据后,他们可以在我将其保存到数据库之前预览他们的输入。 Their Preview is a Razor component and contains an html button to submit.他们的 Preview 是一个 Razor 组件,包含一个 html 提交按钮。

The problem I have is if a customer is click happy, he may click the button multiple times creating multiple copies.我遇到的问题是,如果客户点击满意,他可能会多次点击按钮创建多个副本。 Therefore I want to disable the button after the first click.因此我想在第一次点击后禁用该按钮。 How can I grab the button's handle?我怎样才能抓住按钮的句柄?

From the CreateForm razor page, I have this embeded Razor component从 CreateForm razor 页面,我有这个嵌入的 Razor 组件

    <CustomerPreviewRequest HeadingToShow="@HeadingToShowPreviewCustomerScreen"
                            onBack="MoveToPreviousPage"
                            CurrentCustomerSubmission="@_model">

    </CustomerPreviewRequest>

inside the CustomerPreviewRequest, here's how I define the button在 CustomerPreviewRequest 中,这是我定义按钮的方式

            <button aria-label="Submit Request." type="submit" class="login100-form-btn" style="background-color:#1a2b57"
                    tabindex="0" id="submitForm">
                Submit Request
            </button>

Do you only want the customer to submit the data once and then disable the submit button?您是否只希望客户提交一次数据,然后禁用提交按钮? You can take a look at this simple demo:你可以看看这个简单的演示:

View:看法:

<p style="text-align:center"> 
    <form id="yourFormId" name="yourFormId" method="post" action="#">

        <input type="text" /><br />
        <input type="submit" class="submitBtn" value="Submit Requestt" />
    </form>
</p>




<!--script to disable the submit button -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">  
</script>
<script type="text/javascript">

$(document).ready(function () {
    $(".submitBtn").click(function () {
        $(".submitBtn").attr("disabled", true);
        return true;
    });
});

</script>

Result:结果:

在此处输入图像描述

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

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