简体   繁体   English

Jsp中的文本框验证

[英]Text Boxes Validations in Jsp

In my Jsp I have two text boxes txt1 and txt2 在我的Jsp中,我有两个文本框txt1和txt2

How can I validate these two text boxes ( txtboxes won't be same...)? 如何验证这两个文本框(txtbox会不同...)?

(I need an alert "Both the places are same") (我需要一个警报“两个地方都一样”)

Here is the code: 这是代码:

  <asp:TextBox runat="server" ID="txt1"></asp:TextBox>

        <asp:TextBox runat="server" ID="txt2"></asp:TextBox>

I would suggest you add a cssClass to them. 我建议您向它们添加一个cssClass。 So you have easier time selecting them. 因此,您可以更轻松地选择它们。 Here is an example: 这是一个例子:

Mark up 标记

<asp:TextBox CssClass="compare" runat="server" ID="txt1">test</asp:TextBox>    
<asp:TextBox  CssClass="compare"  runat="server" ID="txt2">test</asp:TextBox>

Javascript Java脚本

var elements = $('.compare');
if (elements.eq(0).html() === elements.eq(1).html()){
   //do stuff
}

Fiddle Demo 小提琴演示

Remember this only does client side validation. 请记住,这仅用于客户端验证。

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

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