顯示具有 javascript 標籤的文章。 顯示所有文章
顯示具有 javascript 標籤的文章。 顯示所有文章

2012年5月26日 星期六

【JavaScript】replace all

<script type="text/javascript">
var visitorName = "Chuck";
var myOldString = "Hello username! I hope you enjoy your stay username.";
var myNewString = myOldString.replace(/username/g, visitorName);

document.write("Old string = " + myOldString);
document.write("<br />New string = " + myNewString);

</script>


Will output as below



Old string = Hello username! I hope you enjoy your stay username.


New string = Hello Chuck! I hope you enjoy your stay Chuck.

2010年8月10日 星期二

How to use Chrome console


if(!window.console)
console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};

console.log('--log--');
console.error('--error--');
console.info('--info--');
console.warn('--warn--');