ASP服务器标签和Jquery.each

时间:2013-06-14 18:59:54

标签: jquery asp.net

所以我想迭代一个内容,并说这个内容有4个文本框

<asp:Content runat="server" ID="FeaturedContent" ClientIDMode="Static" ContentPlaceHolderID="MainContent" class="Tester">
            Property ID:
            <asp:TextBox ID="PersonIDLabel1" runat="server" class="PersonalIDLabel1" onBlur="textBlur(event)" />
            <br />
            LastName:
            <asp:TextBox ID="LastNameTextBox" runat="server" ClientIDMode="Static" onBlur="textBlur(event);" />
            <br />
            FirstName:
            <asp:TextBox ID="FirstNameTextBox" runat="server"  ClientIDMode="Static" onBlur="textBlur(event);"/>
            <br />
            Appraisal Comapny:
            <asp:TextBox ID="HireDateTextBox" runat="server"  ClientIDMode="Static" onBlur="textBlur(event);"/>
            <br />
            Appraisal value:
            <asp:TextBox ID="EnrollmentTextBox" runat="server"  ClientIDMode="Static" onBlur="textBlur(event);"/>
            <br />

我想使用jquery获取文本框的所有值,这里是我的代码:

$("#FeaturedContent").each(function (index) {
            console.log($(this).val());  
        }); 

我也试过

$(".Tester").each(function (index) {
            console.log($(this).val()); 

        });

$("#MainContent").each(function (index) {
           console.log($(this).val()); 

        });

$("#Content").each(function (index) {
           console.log($(this).val()); 

        });

$("#TextBox").each(function (index) {
           console.log($(this).val()); 

        });

任何想法?我甚至可以获得ASP标签吗?

3 个答案:

答案 0 :(得分:2)

IIRC asp:Content服务器控件不会为自己生成html。只需在div中包装此控件内部的内容:

<asp:Content runat="server" ID="FeaturedContent" ClientIDMode="Static" ContentPlaceHolderID="MainContent" class="Tester">
<div id="wrapper">
  Property ID:
  <asp:TextBox ID="PersonIDLabel1" runat="server" class="PersonalIDLabel1"  onBlur="textBlur(event)" />
  <br />
  ...
</div>
</asp:Content> 

并且做:

$("#wrapper input").each(function (index) {
  console.log($(this).val());  
}); 

答案 1 :(得分:0)

试试这个

 $("#<%=FeaturedContent.ClientID%> input").each(function () {
        console.log($(this).val());  
    }); 

答案 2 :(得分:0)

也许你可以在你的javascript函数中使用类似的东西:

var myAnswers[] = $('.class').Content().ToArray();