我从你的问题假设你有li元素的列表,并为每个要输出textn其中n是在列表中的项目的一开始的索引。如果是关于...
$("li").each(function(i) {
$(this).text("text"+(i+1));
});
编辑在回答你的问题的更新,你可以做到这一点使用类似...
$("li").each(function() {
// Use regular expressions to extract the numerical index from the text...
// This appears to be what you intend from your question
var index = $(this).text().replace(/title(\d+)/, "$1");
// Append an element containing the description to the li element
$(this).append("<span class=\"col2\">description-" + index + "</span>");
});
再怎么使用CSS定位,有点像。 ..
/* Used to stop float overflowing the list item */
li { overflow: hidden; }
/* Float the col2 element to the right with a consistent width so
* all col2 elements appear aligned */
li .col2 { float: right; width: 25%; }
编辑忽略上面的JavaScript,我想你只需要HTML和CSS。为了让显示为表中的列表...
<li>
<span class="col1">Title 1</span>
<span class="col2">Description 1</span>
</li>
然后用浮来定位项目,它不会工作表完全相同的方式表的工作方式自动划分的空间,但它可能将不得不你需要的效果。上面的CSS例子是做这件事,你可以使用花车反对...
li { overflow: hidden; /* Row level styling */ }
li .col1 { float: left; width: 75%; }
li .col2 { float: right; width: 25%; }
或者可以叠加彩车旁边彼此
li { overflow: hidden; /* Row level styling */ }
li .col1 { float: left; width: 25%; }
li .col2 { float: left; width: 50%; }
li .col3 { float: left; width: 25%; }
我已经做了小提琴.. http://jsfiddle.net/g8Xkp/
你怎么做*什么*? – Jamiec
调整文本意味着什么? –
这确实不足以帮助我们。请发布更多信息,也许有一些代码是你已经尝试过的,这也是你尝试这样做的原因,因为你可能会以错误的方式解决它。 –