Home  >  Article  >  Web Front-end  >  How to click a certain row in html and the corresponding data will be displayed, and the amount should be displayed with thousands separators_html/css_WEB-ITnose

How to click a certain row in html and the corresponding data will be displayed, and the amount should be displayed with thousands separators_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:04:291948browse


回复讨论(解决方案)


转换千位分隔写了一个,楼主试下。针对的正整数,小数或者负数还得提前处理下。
关于点击切换选项显示不同的数据,可以onchange事件来从后台去相应的值赋值

        <script>        var test = "1232356788800001";        var i = test.length%3 > 0 ? Math.floor((test.length/3)) : (test.length/3)-1;        var a  = test.split("");        for (var x = 1; x<i+1; x++) {        a.splice(-3*x-x+1, 0, ",");        };        alert(a.join(""));        </script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style></style><script language="javascript">window.onload=function(){	var oText=document.getElementById('text');	oText.onkeyup=function()	{		this.value=commafy(this.value);	}	}function commafy(value){	var tmp=value.replace(/[,]/g,'').split('').reverse().join('');	alert(tmp);	tmp=tmp.replace(/(\d{3})(?=\d)/g,'$1,');	return tmp.split('').reverse().join('');	}</script></head><body><input type="text" id="text" />    </body></html>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn