Javascript将变量传递给Jquery

时间:2012-01-25 08:59:03

标签: javascript jquery asp.net

<script type="text/javascript">

function DoThings()
{
 var txt = txtbox.value;

 txt = /* passed info from code behind */
}


$(function() { var Tags=[ txt ]; $( "txtbox2").autocomplete({source: Tags});});

</script>

但我想将其移至页面。我不确定如何将变量“txt”发送到我的jquery函数

1 个答案:

答案 0 :(得分:1)

使函数具有return语句。

function DoThings() {
   var txt = txtbox.value;
   txt = /* passed info from code behind */
   return txt; //return it.
}

$(function() { 
    var Tags=[DoThings()]; $("#txtbox2").autocomplete({source: Tags});});