在jQuery和其他javascript全局变量之间传递变量

在jQuery和其他javascript全局变量之间传递变量,javascript,jquery,Javascript,Jquery,我很难让我在jquery中定义的函数读取我在别处定义的javascript值。 例如,我在jquery中定义了一个函数 var parentImg = ''; //global variable. $(document).change(function() { if ($("#parentImage option:selected").val()) parentImg = $("#parentImage option:selected").val(); alert(pare

我很难让我在jquery中定义的函数读取我在别处定义的javascript值。 例如,我在jquery中定义了一个函数

var parentImg = ''; //global variable.

$(document).change(function() {
  if ($("#parentImage option:selected").val())
    parentImg = $("#parentImage option:selected").val();
    alert(parentImg);
});

$(function(){
    $('#swfuploadcontrol').swfupload({
        upload_url: "upload-file.php?page=<?php echo $htmlFile; ?>&parentImg=" + parentImg});})
var parentImg=''//全局变量。
$(文档).更改(函数(){
if($(“#父图像选项:选中”).val()
parentImg=$(“#parentImage选项:选中”).val();
警惕(家长干预);
});
$(函数(){
$('swfuploadcontrol')。swfupload({
upload_url:“upload file.php?page=&parentImg=“+parentImg});})
但我不能让它读取我在“parentImg”顶部定义的全局变量。jquery中定义的一切似乎都生活在自己的空间中,不与外部世界交互

你知道我如何通过jquery和其他代码来回传递这些值吗


如何将“parentImg”变量值与“upload\u url”变量一起长时间传递?

您正在设置一个可供双方使用的变量,这很好……jQuery没有任何自己的变量,它都是JavaScript。问题是您的代码触发的顺序,
文档.ready
处理程序是否按正确的顺序绑定

现在,您正在绑定到
文档
上的
更改
事件(可能是为了捕获冒泡的
更改
事件?…这可能就在元素上),但这将在
.swfupload()
调用之后运行(该调用在
document.ready
上运行)