<script language="javascript" type="text/javascript"> var a=document.all.getElementById("id").value="";
 alert(a);
</script>
结果无弹出值!,请问是什么原因?

解决方案 »

  1.   

    var a=document.all.getElementById("id").value=""; 
    ---------
    请问,你这句是想做什么呢?
      

  2.   

    document.all.getElementById---------
    有这样的语法吗?
      

  3.   

    document.all.getElementById
    --------
    换成
    document.getElementById
      

  4.   

    var test=document.getElementById("id");
    test.value;
      

  5.   

    几个错误,首先,没有document.all.getElementById("id").value这种用法,其次,要在空间加载完以后才能取得其id,否则都会错误
    正确方法如下<script language="javascript" type="text/javascript"> 
    window.onload=function(){
    var a=document.getElementById("id").value=""; 
    alert(a); 
    }</script> 
    <html>
    <body>
    <div id=id></div>
    </body>
    </html>
      

  6.   


    忘记说了
    你还得有个对象的ID叫做 "id"
      

  7.   

    <script language="javascript" type="text/javascript"> var fk=document.form1.flashimgtotal.value;
     
     var a=document.form1.select.options[fk-4].text;
    var b=document.form1.select.options[fk-3].text;
    var c=document.form1.select.options[fk-2].text;
    var d=document.form1.select.options[fk-1].text;
    var kl=a+"|"+b+"|"+c+"|"+d+"|";
    alert("kl");
    </script>
    网页中有一个表单FORM1,里面有个下啦列表,调用了数据库里的值,我现在想用alert获取考虑kl的值,可怎么试都没有弹出值。
      

  8.   

    因为你用错了,下面这样用,看注释<script language="javascript" type="text/javascript"> 
    window.onload=function(){
    alert(document.form1.aaa.options[1].text ); //引用的第一个名字form1是form的name属性,后面引用select的name属性,这里是aaa
    }</script> 
    <html>
    <body>
    <form name=form1>
    <select name=aaa>
    <option value=1>1</option>
    <option value=2>2</option>
    </select>
    </form>
    </body>
    </html>
      

  9.   

    <select name=select> 这是我的select name
      

  10.   

    检查下你的form的name属性,如果是form1的话请检查下你调用这个函数的地方,是否在window.onload之后
      

  11.   

    如果不是在window.onload之后不行吗?谢谢了,在麻烦你一下,我要处理的问题是?<div id="sasFlashFocus27"></div>
    <script src="admin/flashimg/flashobj.js" type="text/javascript"></script>
    <script src="admin/flashimg/swfobject.js" type="text/javascript"></script>
    <script>
    var flashimgtotal=document.form1.flashimgtotal.value;
    var a=document.form1.aaa.options[flashimgtotal-4].text;
    var b=document.form1.aaa.options[flashimgtotal-3].text;
    var c=document.form1.aaa.options[flashimgtotal-2].text;
    var d=document.form1.aaa.options[flashimgtotal-1].text;
    var okl=a+"|"+b+"|"+c+"|"+d+"|";
    var jj;  ‘我现在这一句好像解析不出来!
    var swf_width=176;
    var swf_height=200;
    var config='3|0xffffff|0x0099ff|50|0xffffff|0x0099ff|0x000000';
    //-- config 参数设置 -- 自动播放时间(秒)|文字颜色|文字背景色|文字背景透明度|按键数字颜色|当前按键颜色|普通按键色彩 --'
    var sohuFlash2 = new sohuFlash("admin/flashimg/demo001.swf", "27", 488, 300, "7");
    jj=ordervalue();
    alert(jj);
    sohuFlash2.addParam("quality", "high");
    sohuFlash2.addParam("wmode", "opaque");
    sohuFlash2.addVariable("image",okl);
    sohuFlash2.addVariable("url","http://www.bqsw.net/");
    sohuFlash2.addVariable("info", "雪狼cs野战! |扔掉犹豫 你的生活你做主|召集中|给父母在海边安个家!");
    sohuFlash2.addVariable("stopTime","4000");
    sohuFlash2.write("sasFlashFocus27");
      </script> 
          <div id="container"></div>
          <script type="text/javascript">
    var s1 = new SWFObject("admin/flashimg/player.swf","ply","488","20","9","#FFFFFF");
    s1.addParam("allowscriptaccess","always");
    s1.addParam("allowfullscreen","false");
    s1.addParam("flashvars","file=admin/flashimg/djrm.mp3&autostart=true");
    s1.write("container");
      </script>
        </div>
      

  12.   

    如果不是在window.onload之后,有可能你的控件还没加载,所以会出错
    正确的做法是<div id="sasFlashFocus27"> </div>
    <script src="admin/flashimg/flashobj.js" type="text/javascript"> </script>
    <script src="admin/flashimg/swfobject.js" type="text/javascript"> </script>
    <script>
        var flashimgtotal;
        var a;
        var b;
        var c;
        var d;
        var okl;
        var swf_width=176;
        var swf_height=200;
        var config='3|0xffffff|0x0099ff|50|0xffffff|0x0099ff|0x000000';
        //-- config 参数设置 -- 自动播放时间(秒)|文字颜色|文字背景色|文字背景透明度|按键数字颜色|当前按键颜色|普通按键色彩 --'
        
        window.onload=function(){
            flashimgtotal=document.form1.flashimgtotal.value;
            a=document.form1.aaa.options[flashimgtotal-4].text;
            b=document.form1.aaa.options[flashimgtotal-3].text;
            c=document.form1.aaa.options[flashimgtotal-2].text;
            d=document.form1.aaa.options[flashimgtotal-1].text;
            okl=a+"|"+b+"|"+c+"|"+d+"|";var jj;  //‘我现在这一句好像解析不出来!
            var sohuFlash2 = new sohuFlash("admin/flashimg/demo001.swf", "27", 488, 300, "7");
            jj=ordervalue();
            alert(jj);
            sohuFlash2.addParam("quality", "high");
            sohuFlash2.addParam("wmode", "opaque");
            sohuFlash2.addVariable("image",okl);
            sohuFlash2.addVariable("url","http://www.bqsw.net/");
            sohuFlash2.addVariable("info", "雪狼cs野战! |扔掉犹豫 你的生活你做主|召集中|给父母在海边安个家!");
            sohuFlash2.addVariable("stopTime","4000");
            sohuFlash2.write("sasFlashFocus27");
        }</script>
    <div id="container"> </div>
    <script type="text/javascript">
        var s1 = new SWFObject("admin/flashimg/player.swf","ply","488","20","9","#FFFFFF");
        s1.addParam("allowscriptaccess","always");
        s1.addParam("allowfullscreen","false");
        s1.addParam("flashvars","file=admin/flashimg/djrm.mp3&autostart=true");
        s1.write("container");
    </script>
    </div>
      

  13.   

    -------您不是说:"如果不是在window.onload之后,有可能你的控件还没加载,所以会出错 
    " 可是以下页面没有按照您的做法也能得到值.我的思路还是从数据库调用数据到form表单再到控件

    var files=teacher[0]+"|"+teacher[1]+"|"+teacher[2];
    -----------------------------------------------------------------------------------
    <div id="teacher">
           <script type="text/javascript">
    var totalresult=document.form1.totalresult.value;
    var teacher = new Array();
    var swf_width=176;
    var swf_height=200;
    var config='3|0xffffff|0x0099ff|50|0xffffff|0x0099ff|0x000000';
    //-- config 参数设置 -- 自动播放时间(秒)|文字颜色|文字背景色|文字背景透明度|按键数字颜色|当前按键颜色|普通按键色彩 --'
    teacher[0]="admin/"+document.form1.select.options[totalresult-3].text;
    teacher[1]="admin/"+document.form1.select.options[totalresult-2].text;
    teacher[2]="admin/"+document.form1.select.options[totalresult-1].text;
    var files=teacher[0]+"|"+teacher[1]+"|"+teacher[2];
    var links='http://z.com/|http://www.zzjy.com/|http://www.zzjy.com/';
    var texts='||';
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ swf_width +'" height="'+ swf_height +'">');
    document.write('<param name="movie" value="style/focus.swf" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="menu" value="false" />');
    document.write('<param name=wmode value="opaque" />');
    document.write('<param name="FlashVars" value="config='+config+'&bcastr_flie='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'" />');
    document.write('<embed src="images/focus.swf" wmode="opaque" FlashVars="config='+config+'&bcastr_flie='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'& menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
    </script>    </div>
      

  14.   

    先用几个变量存储从数据库得到的值,然后再onload方法里将得到的值写到控件里就没问题了,你注意下这个顺序,我在这里测试通过了的
    你得保证:1.在调用form控件之前已经控件已经加载完毕,也就是window.onload方法里以用这个控件
               2.你在给这个空间赋值的时候是已经得到数据库的值的
    你按这个顺序做下
      

  15.   

    你可以在你的teacher[0]="admin/"+document.form1.select.options[totalresult-3].text;
    这句话前面加个if(!document.getElementById(document.form1.select.options[totalresult-3])) alert("控件未加载") 来测试空间到底有没有加载
      

  16.   

    我确定我没用windows.onload方法,能得到值能输出var files=teacher[0]+"|"+teacher[1]+"|"+teacher[2]; alert(files)没问题的
      

  17.   

    将下面几个值放在window.onload方法中作为全局变量,然后再在你的div中引用flashimgtotal=document.form1.flashimgtotal.value;
            a=document.form1.aaa.options[flashimgtotal-4].text;
            b=document.form1.aaa.options[flashimgtotal-3].text;
            c=document.form1.aaa.options[flashimgtotal-2].text;
            d=document.form1.aaa.options[flashimgtotal-1].text;
            okl=a+"|"+b+"|"+c+"|"+d+"|";var jj;  //‘我现在这一句好像解析不出来!
      

  18.   

    你的意思是你现在teacher[0]="admin/"+document.form1.select.options[totalresult-3].text; 
    teacher[1]="admin/"+document.form1.select.options[totalresult-2].text; 
    teacher[2]="admin/"+document.form1.select.options[totalresult-1].text; 
    //上面值能得到
    var files=teacher[0]+"|"+teacher[1]+"|"+teacher[2];  //这句得不到?
      

  19.   

    这个window.onload方法已经成功了,谢谢你的指导,可是我现在很想知道为什么我的另外一个页面却没用你那种方法却能出来结果。14楼我已经叙述了。麻烦您再指点一下。!
      

  20.   

    1.那个框出来的方法用[code=XXX]  xxx=HTML或者JScript
    2.你另外个地方不用可以出来是因为加载顺序的问题,有可能在你调用的时候已经加载完了,有可能还没有 
      

  21.   


    <div id="sasFlashFocus27"> </div>
    <script src="admin/flashimg/flashobj.js" type="text/javascript"> </script>
    <script src="admin/flashimg/swfobject.js" type="text/javascript"> </script>
    <script>    window.onload=function(){
            flashimgtotal=document.form1.flashimgtotal.value;
            a=document.form1.aaa.options[flashimgtotal-4].text;
            ");
        }</script>
    <div id="container"> </div>
    <script type="text/javascript">
        var s1 = new SWFObject("admin/flashimg/player.swf","ply","488","20","9","#FFFFFF");
        s1.addParam("allowscriptaccess","always");
        s1.addParam("allowfullscreen","false");
        s1.addParam("flashvars","file=admin/flashimg/djrm.mp3&autostart=true");
        s1.write("container");
    </script>
    </div>看来这个方法很不错。
      

  22.   

    你说的很对,谢谢,我这个问题解决了。真的很谢谢你。你ASP学的很好啊,你对做网站有什么好的建议吗?
      

  23.   

    我是JSP系的- - 
    技术上用SSH,或者JSP+ajax
    也是个新人,所以谈不上什么建议了,只是觉得网站要想成功,创意是最重要的吧(如开心农场,虽然可能算不上网站)
      

  24.   

    406931901这是我的朋友,我们两一起做的,他也学过SSH,也想和你交个朋友!呵呵
      

  25.   

    <script language="javascript" type="text/javascript"> var a=document.all.getElementById("id").value=""; 
    alert(a); 
    </script> 
    重新写成:
    <script language="javascript" type="text/javascript"> 
    window.onload=function AlertMessage()
    {
    var a=document.getElementById("id").value=""; 
    alert(a); 
    }
    </script> 
      

  26.   

    我要也打算学JSP,还没有开始学,学校有这课,还没开,你给我点学JSP的建议吧?
      

  27.   

    我无语。
    var a=document.all.getElementById("id").value=""
    alert(a); 这样还会有值?是不是alert一个空白?
      

  28.   


    var a=document.all.getElementById("id").value=""; 
    alert(a); 等于
    document.all.getElementById("id").value=""; 
    var a=document.all.getElementById("id"); 
    alert(a);
     
    你将 id 控件的值清空了,你还觉得他怎么出值?
      

  29.   

    getElementById是document成员提供的方法,document.all返回的是一个集合对象,它不具有这样一个方法
    可以这样取得元素并为其赋值
    var a = document.all('id').value='';
    这是一个值传递过程
    故楼主可以这样写:
    <script language="javascript" type="text/javascript"> 
    var a=document.all("id").value=""; 
    alert(a); 
    </script> 
    测试了没问题的
      

  30.   

    <script language="javascript" type="text/javascript"> var a=document.all.getElementById("id").value=""; 
    alert(a); 
    </script> 
    JS放置在页面的位置不对,必须得是该标记呈现出来后才行.
      

  31.   

    错误一:不是document.all.getElementById("id")
    而是document.getElementById("id")
    错误二:应该是
    document.getElementById("id").value=""; 
    这个操作应该没有返回值的。是赋值操作。
    尽量不要使用id作为id属性值