jquery tablesorter-格式化货币-我做错了什么?
我在处理货币时遇到问题,然后我使用了这个代码jquery tablesorter-格式化货币-我做错了什么?,jquery,tablesorter,Jquery,Tablesorter,我在处理货币时遇到问题,然后我使用了这个代码 <script type='text/javascript'> $(document).ready(function () { $("#3dprojector").tablesorter(); } ); // add parser through the tablesorter addParser method $.tablesorter.addPar
<script type='text/javascript'>
$(document).ready(function () {
$("#3dprojector").tablesorter();
}
);
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'thousands',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.replace('$','').replace(/,/g,'');
},
// set type, either numeric or text
type: 'numeric'
});
$(function() {
$("table").tablesorter({
headers: {
1: {//zero-based column index
sorter:'thousands'
}
}
});
});
</script>
$(文档).ready(函数(){
$(“#3dprojector”).tablesorter();
}
);
//通过tablesorter addParser方法添加解析器
$.tablesorter.addParser({
//设置一个唯一的id
id:'千',
is:函数{
//返回false,因此不会自动检测到此解析器
返回false;
},
格式:函数{
//格式化数据以进行规范化
返回s.replace(“$”,“)。replace(/,/g)”;
},
//设置类型,数字或文本
键入:“数字”
});
$(函数(){
$(“表”).tablesorter({
标题:{
1:{//从零开始的列索引
分拣员:“数千”
}
}
});
});
问题是,它只能按一种方式排序。我不确定我是否用对了解析器。此脚本在我的网站上完成/head标记之前。感谢您的帮助:-)您实例化了2次tablesorter,一次在3dproject的table once上(由于3次实例化,失败的可能性很高)
jQuery(函数($,未定义){
//通过tablesorter addParser方法添加解析器
$.tablesorter.addParser({
//设置一个唯一的id
id:'千',
is:函数{
//返回false,因此不会自动检测到此解析器
返回false;
},
格式:函数{
//格式化数据以进行规范化
返回s.replace(“$”,“)。replace(/,/g)”;
},
//设置类型,数字或文本
键入:“数字”
});
$(“表”).tablesorter({
标题:{
1:{//从零开始的列索引
分拣员:“数千”
}
}
});
});
这对你有什么好处?如果出现粘贴控制台错误
$(“#3dprojector”)
?更改为$('#3dprojector')
!不要以数字开头ID名称
<script type='text/javascript'>
jQuery(function($,undefined) {
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'thousands',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
return s.replace('$','').replace(/,/g,'');
},
// set type, either numeric or text
type: 'numeric'
});
$("table").tablesorter({
headers: {
1: {//zero-based column index
sorter:'thousands'
}
}
});
});
</script>