我有一個簡單的函數,它可以改變傳遞給它的變量。但退出該函數後,該變量返回到舊值。我不知道爲什麼或如何解決它變量在退出jquery函數後保留其舊值
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var a='test';
$().doit(a);
alert(a);
});
(function ($) {
$.fn.doit = function (input) {
alert(input);
input='new';
alert(input);
};
}(jQuery));
</script>
</head>
<body>
</body>
</html>
閱讀http://stackoverflow.com/questions/2835070/is-there-thing-like-pass-by-value-pass-by-reference-in-javascript和http://stackoverflow.com/questions/ 518000/IS-JavaScript的一個通按引用-或通按值的語言 –