我不理解函數範圍。點擊時我有一個按鈕顯示一個帶有textarea的對話框。在那個textarea裏面,我用一個網址填充它,然後有人可以爲他們的相機設置進行復制。jquery函數範圍
<button id="axis-details" onclick="apikey('<?php echo $result_cameras[$i]["camera_hash"]; ?>');">API Key</button>
function apikey(camerahash)
{
var $key = "http://myhost.com/notify.php/" +camerahash;
return $key;
}
$(document).ready(function() {
var $dialog = $('<div></div>');
$dialog.append('Please copy this key for camera setup: ')
.append('<p><textarea id=\"textbox\">'+apikey(camerahash)+'</textarea></p>') //ERROR here that camerahash is not defined
.append('<p>For more information see: <a href=\"http://www.myhost.com/forum/2-quickstart-docs\">setup</a></p>');
$dialog.dialog({
autoOpen: false,
title: 'API Key'
});
$('#axis-details').click(function(e) {
e.preventDefault();
$dialog.dialog('open');
});
});
函數apikey(camerahash)確實返回我期望的值。我得到上面指出的camerahash未定義的錯誤。我究竟做錯了什麼?
在你的代碼永遠不會初始化'camerahash'沒有你忘了什麼? – 2012-03-08 16:20:52
指出camerahash未定義的錯誤是因爲camerahash沒有定義......不知道可以得到多少明確 – jbabey 2012-03-08 16:25:54