'function (result) {  $("#Text1").val(result);}'
上面是个字符串
有没有办法转成函数并执行呢?
高手帮忙,要怎么写呢

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready( function() {
    var str = 'function (result) { $("#Text1").val(result);}';
    str = 'var foo = ' + str;
    eval(str);
    foo('test');
    });
    </script>
    </head><body>
    <input type="text" id="Text1" />
    </body>
    </html>