我有一个字符串,我想用小“i”替换每个大写“I”,用大写“I”替换每个小“i”。如您所见,如果我分两个阶段执行此操作,它只是将其转换,然后将其转换回以前的状态。那么我将如何一次完成这一切呢?
<html>
<head>
<script type="text/javascript">
function init() {
text = document.getElementById('test');
newtext = text.innerHTML.replace(/I/g, "i");
newtext = newtext.replace(/i/g, "I");
text.innerHTML = newtext;
}
</script>
</head>
<body onload="init()">
<div id="test">
THIS IS SOME TEST
</div>
</body>
</html>