代码的目标是每当点击按钮时旋转字符串。
对于如..如果输入字符串为计算器
后一点击就成了WSTACKOVERFLO
后的下次点击它成为OWSTACKOVERFL
等等...
我只想在JavaScript中使用闭合来解决它。
在JavaScript中使用闭合来旋转字符串
<html>
<script>
var executeMe = function() {
var word=document.getElementById("word").value;
function(){
word=word.slice(-1)+word.slice(0,-1);
return word;
}
}();
function myFunction(){
document.getElementById("demo").innerHTML = executeMe();
}
</script>
<body>
<p>Rotate the String.</p>
<input type="string" name="word" id="word"></input>
<button type="button" onclick="myFunction()">Rotate</button>
<p id="demo"></p>
</body>
</html>
为什么你的函数里面有函数? – Weedoze