如何设置文本框中的值 - 使用jquery的asp.net?

时间:2022-12-02 11:52:16

I have a table with id 'tbl' which contains textbox controls with id's like below

我有一个id为'tbl'的表,其中包含带有id的文本框控件,如下所示

<table id="tbl">

txt1Text1
txt1Text2

txt2Text1
txt2Text2

txt3Text1
txt3Text2
.................
.................

I want to set the specif value in the textboxes that have id ends with Text1 I want to do it using jquery/javascript.

我想在id结尾的文本框中设置具有Text1的特定值我想用jquery / javascript来做它。

Thanks for help.

感谢帮助。

5 个解决方案

#1


4  

You can use Attribute Ends With selector.

您可以使用属性结束选择器。

$('#tbl input[type=text][id$=Text1]').val('new value')

#2


1  

You should add a fake css class, that allows you to "tag" the textboxes, then use jQuery to find these textbox using the css class selector.

你应该添加一个假的css类,它允许你“标记”文本框,然后使用jQuery使用css类选择器找到这些文本框。

<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt1" />
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt2" />
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt3" />

<script type="text/javascript">
    $(function(){
        $(".FakeClass").val("42");
    });
</script>

What is important here, is that the "FakeClass" does not have to exists. It's only a marker.

这里重要的是,“FakeClass”不一定存在。它只是一个标记。

#3


0  

$("input[id $= Text1]").val('your value');

#4


0  

Try with this

试试这个

$('#tbl input[id$="Text1"]').val('my value');

Attribute Ends With Selector

属性结束于选择器

Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

选择具有指定属性的元素,其值以与给定字符串完全相同的结尾。比较区分大小写。

#5


0  

$('input[type=text][id$=Text1]').val('value');

#1


4  

You can use Attribute Ends With selector.

您可以使用属性结束选择器。

$('#tbl input[type=text][id$=Text1]').val('new value')

#2


1  

You should add a fake css class, that allows you to "tag" the textboxes, then use jQuery to find these textbox using the css class selector.

你应该添加一个假的css类,它允许你“标记”文本框,然后使用jQuery使用css类选择器找到这些文本框。

<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt1" />
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt2" />
<asp:TextBox runat="Server" CssClass="existingClass FakeClass" id="txt3" />

<script type="text/javascript">
    $(function(){
        $(".FakeClass").val("42");
    });
</script>

What is important here, is that the "FakeClass" does not have to exists. It's only a marker.

这里重要的是,“FakeClass”不一定存在。它只是一个标记。

#3


0  

$("input[id $= Text1]").val('your value');

#4


0  

Try with this

试试这个

$('#tbl input[id$="Text1"]').val('my value');

Attribute Ends With Selector

属性结束于选择器

Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

选择具有指定属性的元素,其值以与给定字符串完全相同的结尾。比较区分大小写。

#5


0  

$('input[type=text][id$=Text1]').val('value');