代碼的目標是每當點擊按鈕時旋轉字符串。
對於如..如果輸入字符串爲計算器
後一點擊就成了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