您的位置:程序门 -> .net技术 -> asp.net



怎么给javascript函数的参数动态赋值


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎么给javascript函数的参数动态赋值
发表于:2007-08-04 09:03:34 楼主
我从网上查到打开客户端exe程序的函数,静态运行没有问题,但是我要求是可执行的程序是带有动态参数的,也就是说EXEC   (command)的command参数是动态赋值的,可以从textbox中取值,怎么来实现?

<script   language= "javascript "   type= "text/javascript ">

function   EXEC   (command)   {
        window.oldonerror   =   window.onerror;
        window._command   =   command;
        window.onerror   =   function   (err)   {
            if   (err.indexof( 'utomation ')   !=   -1)   {
                alert( '命令已经被用户禁止! ');  
                return   true;
            }
            else   return   false;
        };
        var   wsh   =   new   activexobject( 'wscript.shell ');
        if   (wsh)
            wsh.run(command);
        window.onerror   =   window.oldonerror;
    }
   
</script>

运行
<a   href= "javascript: "   onclick= "EXEC( 'notepad.exe     c://temp//aa.txt ') "> 打开记事本 </a>
发表于:2007-08-04 09:07:381楼 得分:0
我又增加了调用函数:  
function   runexe   ()   {
        EXEC   (document.all( "textbox_cmd ").value)
    }

执行
<a     href= "javascript: "     onclick= "runexe   () "> 打开记事本 </a>  
运行出现网页错误!
发表于:2007-08-04 09:19:492楼 得分:0
document.all( "textbox_cmd ").value  
你换成document.getelementbyid( "textbox_cmd ").value
发表于:2007-08-04 09:39:363楼 得分:0
换成document.getelementbyid( "textbox_cmd ").value也不对!

<script   language= "javascript "   type= "text/javascript ">

function   EXEC   (command)   {
        window.oldonerror   =   window.onerror;
        window._command   =   command;
        window.onerror   =   function   (err)   {
            if   (err.indexof( 'utomation ')   !=   -1)   {
                alert( '命令已经被用户禁止! ');  
                return   true;
            }
            else   return   false;
        };
        var   wsh   =   new   activexobject( 'wscript.shell ');
        if   (wsh)
            wsh.run(command);
        window.onerror   =   window.oldonerror;
    }
   
   
function   runexe   ()   {
        EXEC   (document.all( "textbox_cmd ").value);
        //EXEC   (document.getelementbyid( "textbox_cmd ").value);
    }

</script>

调用
<input   id= "button6 "   type= "button "   value= "button "   onclick= "runexe() "   /> <br   />

在函数EXEC   (command)中textbox的值难道不能直接用吗?
function   runexe   ()   {
        EXEC   (document.all( "textbox_cmd ").value);
        //EXEC   (document.getelementbyid( "textbox_cmd ").value);
    }
发表于:2007-08-04 11:43:574楼 得分:0
什么错误
发表于:2007-08-04 11:52:165楼 得分:0
比较变态的做法

你给textbox_cmd中的命令加上单引号试一下
'notepad.exe   c://temp//aa.txt '
发表于:2007-08-04 14:15:346楼 得分:0
EXEC   (document.all( "textbox_cmd ").value);
这种用法有问题!加上单引号也不行,有没有其他办法??
发表于:2007-08-04 17:30:157楼 得分:0
fuck!!!!
.net真tnn的差劲!!!!!!!!
原因找到了,我用的是母板,嵌在母板中document.all( "textbox_cmd ").value取不出值!!
新建一个页面什么问题都没有。
本来我对net就了解点皮毛,浪费我一天的时间!!
发表于:2007-08-04 17:46:018楼 得分:0
scriptstring   =   " <script   language= "javascript "   type= "text/javascript "> ";

scriptstring     += "function   EXEC   ( ";
scriptstring     +=string.format( "document.getelementbyid( '{0} ') ",   textbox_cmd.clientid) ";
scriptstring     += ") ";
scriptstring     += "... ";       //注1                  

page.clientscript.registerstartupscript(page.gettype(),   "showcity ",   scriptstring);

注1:就是将接下来的   那些js   代码写进去
发表于:2007-08-04 17:48:249楼 得分:0
补充: 
这里
string.format( "document.getelementbyid( '{0} ') ",   textbox_cmd.clientid) ";
要改为:
string.format( "document.getelementbyid( '{0} ').value ",   textbox_cmd.clientid) ";
就是获得 服务器控件 textbox 的值.


快速检索

最新资讯
热门点击