function myfun(element)
{
  element.value=<%=text>;
}
<%
  text="hello"
%>我想在myfun里给elelment.value赋值,用下面的text变量,这样写不行,想请高手帮帮忙~在此谢过了先~~

解决方案 »

  1.   

    可以,<% 
      text="hello" 
    %>function myfun(element) 

       alert(<%=text>);
       element.value= <%=text> ; 
      

  2.   

     element.value= "<%=text>" ; 
      

  3.   

    <%
    dim s
    s="hello"
    %>
    <script>
    alert("<%=s%>");
    </script>
      

  4.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.htm.cs" Inherits="test" %><!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 runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
        
    </head>
    <body>
        <form id="form1">
        <div>    <%
         dim testinasp;
            testinasp="hello world!";
         %>     <script type="text/javascript">
         alert("<%=testinasp %>");
         </script>
        </div>
        </form>
    </body>
    </html>弹出的对话框是<%=testinasp%>
    不是hello world!
      

  5.   

    <% string testinasp ="hello world!"; %>
        <script type="text/javascript"> 
            alert("<%=testinasp %>"); 
    </script>
      

  6.   

    对了,我是在一个htm页里写的~
    能行么?
      

  7.   

    你这个文件使用了外部程序,而不是内联程序,所以不行。
    而且asp.net的内联代码不是用<%%>标记的,而是用<script runat=server></script>标记的。
    而且你的代码头部定义使用c#,但是代码中却是用的是vb的语法。
    这样修改试试:
    <%@ Page Language="C#"%> <!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 runat="server"> 
         <title> 无标题页 </title>      
    </head> 
    <body> 
         <form id="form1"> 
         <div>     <script runat="server">
         
         String   testinasp="hello world!"; 
         >/script>      <script type="text/javascript"> 
         alert(" <%=testinasp %> "); 
          </script> 
         </div> 
         </form> 
    </body> 
    </html>
      

  8.   

    晕,大哥,你太有才了,在html文件里写C#代码。
    扩展名需要修改为aspx。
      

  9.   

    但我就是要用htm啊~
    改过来当然行,但是不让改啊~
    我现在就是在htm里想连接数据库,现在想查看变量的值,不知道怎么查看,就想用这种方式访问一下,看是否正确了~
    我刚接触这东西,好多都不懂呢~呵呵
      

  10.   

    Html里面不能写C#的代码。
    如果想用Htm来实现的话,只能使用Ajax技术。
      

  11.   

    你不可以把变量发到一个<input type="hidden" id="test" name="test" value="" />吗?
    然后再调用
    function myfun(element) 

      element.value=document.all.test.value ;