admin管理员组文章数量:1426454
I have a table with id 'tbl' which contains textbox controls with id's like below
<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.
Thanks for help.
I have a table with id 'tbl' which contains textbox controls with id's like below
<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.
Thanks for help.
Share Improve this question edited Sep 25, 2012 at 12:56 Muhammad Akhtar 52.2k37 gold badges139 silver badges191 bronze badges asked Sep 25, 2012 at 12:50 Azeem Raza TayyabAzeem Raza Tayyab 631 silver badge6 bronze badges 5- please specify whether the control is a html control or server control – cc4re Commented Sep 25, 2012 at 12:51
- Please note one point, he want to set the value of only those controls, that have id ends with 'Text1'. In question, there are 3 controls. – Muhammad Akhtar Commented Sep 25, 2012 at 12:55
- 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. In fact, you should also descrive how you create the textboxes. One by one? using a databound control? using mvc? created on the fly? With the answer to this question, you will get far more better answers as there are probably thousands way to solve the issue. – Steve B Commented Sep 25, 2012 at 12:56
- @SteveB, post that answer and I'll upvote it. That seems to be the "best practice" answer. – Neil Commented Sep 25, 2012 at 12:58
- @Neil: I will when azeemraza will give more details on how he creates the textboxes. – Steve B Commented Sep 25, 2012 at 13:01
5 Answers
Reset to default 5You can use Attribute Ends With
selector.
$('#tbl input[type=text][id$=Text1]').val('new value')
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.
<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.
$("input[id $= Text1]").val('your value');
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 parison is case sensitive.
$('input[type=text][id$=Text1]').val('value');
本文标签: javascriptHow to set the value in the textboxesaspnet using jqueryStack Overflow
版权声明:本文标题:javascript - How to set the value in the textboxes - asp.net using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745446597a2658691.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论