本文介绍了检查的最佳方式,如果3文本框为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个文本框,我想检查,如果放在一起,他们全部加起来超过空白更大。
什么是实现这一目标的最佳途径?

I have 3 textboxes and I want to check if put together they all add up to greater than blank.What's the best way to accomplish that?

    <asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
    <asp:TextBox ID="tbHour" runat="server"></asp:TextBox>
    <asp:TextBox ID="tbMinutes" runat="server"></asp:TextBox>

<asp:CustomValidator ID="cvDateControlValidator" runat="server" ErrorMessage="Invalid Date"
    ValidateEmptyText="True" ClientValidationFunction="validateDateOnClient" ControlToValidate="tbDate"
    Display="Dynamic"></asp:CustomValidator>

<script type="text/javascript">
    function validateDateOnClient(sender, args) {
        if (args.Value.length > 0)
            args.IsValid = false;

        return args.IsValid;
    }

</script>

一个建议是:

if (tbDate.value != '' || tbHour.value != '' || tbMinutes.value != '')

我要确保tbDate,tbHour,tbMinutes在一起比空白更大之前,我执行客户端验证。

I want to make sure tbDate, tbHour, tbMinutes together is greater than blank before I perform the client-side validation.

推荐答案

我认为你可以这样做一个 CustomFieldValidator

I think you can do this with a single CustomFieldValidator.

我觉得你很接近你自己的答案。我会总和长度是这样的:

I think you are very close to the answer on your own. I would sum the lengths like this:

if (tbDate.value.length + tbHour.value.length + tbMinutes.value.length > 0)

这篇关于检查的最佳方式,如果3文本框为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:49