admin管理员组文章数量:1290394
I want to align the contents of 5 input fields (named "Textfield1" ... "Textfield5") on one page to the right by means of jQuery calling CSS. I tried this:
for (var i=1; i<=5; i++)
{
JQuery('#'+ff_getElementByName('"Textfield" + [i]').id).css('text-align', 'right');
}
and I tried this:
for (var i=1; i<=5; i++)
{
var2 = "Textfield" + [i];
JQuery('#'+ff_getElementByName('var2').id).css('text-align', 'right');
}
Neither one works. How to make it work? Thanks.
I want to align the contents of 5 input fields (named "Textfield1" ... "Textfield5") on one page to the right by means of jQuery calling CSS. I tried this:
for (var i=1; i<=5; i++)
{
JQuery('#'+ff_getElementByName('"Textfield" + [i]').id).css('text-align', 'right');
}
and I tried this:
for (var i=1; i<=5; i++)
{
var2 = "Textfield" + [i];
JQuery('#'+ff_getElementByName('var2').id).css('text-align', 'right');
}
Neither one works. How to make it work? Thanks.
Share Improve this question asked May 10, 2013 at 9:07 user2317194user2317194 2211 gold badge4 silver badges13 bronze badges 3- 1 Hey, what does your html look like? – WheretheresaWill Commented May 10, 2013 at 9:09
- The html just assigns the name to an input field. The html is ok because JQuery('#'+ff_getElementByName('Textfield1').id).css('text-align', 'right'); works!! – user2317194 Commented May 10, 2013 at 9:11
-
Post the
ff_getElementByName
function also.. – palaѕн Commented May 10, 2013 at 9:11
5 Answers
Reset to default 2I think CSS will do this.
<input type="text" id="text1" class="align_text"/>
<input type="text" id="text2" class="align_text"/>
<input type="text" id="text3" class="align_text"/>
<input type="text" id="text4" class="align_text"/>
<input type="text" id="text5" class="align_text"/>
<input type="text" id="text6" class="align_text"/>
.align_text { text-align: right; }
The following code works, and here is a link to a demo: jsfiddle
for (var i=1; i<=5; i++)
{
fields = "Textfield" + i;
$('#' + fields).css('text-align', 'right');
}
This should work:
for (var i = 1; i <= 5; i++) {
JQuery('#' + ff_getElementByName("Textfield" + i).id).css('text-align', 'right');
}
OR
for (var i = 1; i <= 5; i++) {
var2 = "Textfield" + i;
JQuery('#' + ff_getElementByName(var2).id).css('text-align', 'right');
}
Try this:
$('[name^="Textfield"]').css('text-align', 'right');
This uses jQuery's Attribute starts with selector
Use the below code:
for (var i=1; i<5; i++)
{
var textfields = "Textfield"+i;
var ids = jQuery("[name="+textfields+"]").attr("id");
JQuery('#'+ids).css('text-align', 'right');
}
本文标签: javascriptAlign textfields right via jQueryCSS and within a for loopStack Overflow
版权声明:本文标题:javascript - Align textfields right via jQueryCSS and within a for loop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741498121a2381925.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论