以段落的形式加上数字
Append as a paragraph with number
如何将其附加为每行自动编号的段落。下面的例子是在listview中。看链接,它在工作。
工作演示但在listview
我的Html代码:
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
<a href="#second" class="ui-btn-right">Next</a>
</div>
<div data-role="content">
<ul data-role="listview" data-theme="a" id="custom-listview">
</ul>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
Js代码$(document).on('pagebeforeshow', '#index', function(){
var split = 'Cook pasta according to directions, chill in ice water, drain.¶Blanch broccoli in boiling water, chill in ice water, drain.¶Use ½ soy sauce to season the chicken, heat oil in no stick pan, brown chicken, and reduce heat and finish cooking.¶Don"t overcook! Slice chicken into 1" strips, turn and cut into ¼" pieces, place into bowl with other ingredients except dressing and soy sauce.¶Mix remainder of soy sauce into dressing and pour over pasta, chicken, and vegetables.¶Toss gently and serve immediately.¶You might like to leave the pasta, chicken, broccoli un-chilled and serve it semi-warm';
var lines = split.split('¶');
$.each(lines, function(key, line) {
$('#custom-listview').append('<li><a href="#">' + line + '</a></li>');
});
$('#custom-listview').listview('refresh');
});
只需声明一个变量,并为每个附加项增加它。
var number = 1;
$.each(lines, function(key, line) {
$('#custom-listview').append('<li><a href="#">' + number + '. ' + line + '</a></li>');
number++;
});
http://jsfiddle.net/Z7uxZ/2/相关文章:
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 测试索引值是否等于某个数字的倍数
- 将数字转换为一定数量的硬币
- 键入最后一位数字后自动提交
- 如何在javascript中迭代数字列表
- Javascript逻辑运算符和字符串/数字
- 如何在javascript中获得与特定数字相等的随机数
- 如果元素's的ID以数字开头
- 递增一个数字而不去掉前导零
- 如何使用JavaScript查找1和N之间的所有数字的总和
- 如何在这里将两个值最低的数字相加
- 如何删除除冒号、数字和'上午'或者'下午'
- 如何为jQuery屏蔽输入插件创建一个允许字母数字、空格和重音字符的掩码
- Javascript排序字符串或数字
- 我想在AngularJS应用程序中创建一个输入数字框,用户不应该在该框上键入十进制数字.(一个整数输入框)
- 将数字四舍五入到小数点后两位
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 正则表达式与数字中的第二个点匹配
- 如何在一行或段落中突出显示一些数字或文本
- 以段落的形式加上数字