我有一个函数取(a,b)
现在有一个文本框输入一个值,通过按钮确认后把值赋予a.
<div><lable>从<input type="text" id="t" />
<button onclick="test();"><b>OK</b></button>
<script type="text/javascript">
//取值
function test();{
var a=document.getElementById("t")
}
不知道错误在哪里 麻烦各位指出

解决方案 »

  1.   

    var a=document.getElementById("t").valuehtml写的实在乱
      

  2.   

    function test(){
    var a=document.getElementById("t").value;
    }
      

  3.   

    function test();{
    var pStart=document.getElementById("a").value
    }
      

  4.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>公交导航</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&services=true"></script>
    </head>
    <body>
    <div style="width:520px;height:340px;border:1px solid gray" id="dituContent"></div>
    </body>
    <div><lable>从<input type="text" id="a" />公司</lable>
    <button onclick="test();"><b>OK</b></button>
    </html>
    <script type="text/javascript">//建立地图
    var map = new BMap.Map("dituContent");
    map.centerAndZoom(new BMap.Point(113.170211,28.187604), 12);
    //取得开始节点
    function test();{
    var pStart=document.getElementById("a").value
    }
    //终点值
    var pEnd = new BMap.Point(113.170211,28.187604);
    //返回路线
    var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
    driving.search(pStart, pEnd);
    </script>
      

  5.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>公交导航</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&services=true"></script>
    </head>
    <body>
    <div style="width:520px;height:340px;border:1px solid gray" id="dituContent"></div>
    </body>
    <div><lable>从<input type="text" id="a" />公司</lable>
    <button onclick="test();">OK</button>
    </html>
    <script type="text/javascript">//建立地图
    var map = new BMap.Map("dituContent");
    map.centerAndZoom(new BMap.Point(113.170211,28.187604), 12);
    //取得开始节点
    function test(){
    var pStart=document.getElementById("a").value;
    }
    //终点值
    var pEnd = new BMap.Point(113.170211,28.187604);
    //返回路线
    var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
    driving.search(pStart, pEnd);
    </script>不要把项目的具体内容泄露出来。
      

  6.   

    function test();{
    var pStart=document.getElementById("a").value;}
    还有你后面driving.search(pStart, pEnd);用到pStart了,所以pStart应该定义为全局的而不是在test()里面定义。
      

  7.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>公交导航</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&services=true"></script>
    </head>
    <body>
    <div style="width:520px;height:340px;border:1px solid gray" id="dituContent"></div>
    </body>
    <div><lable>从<input type="text" id="a" />公司</lable>
    <button onclick="test();">OK</button>
    </html>
    <script type="text/javascript">//建立地图
    var map = new BMap.Map("dituContent");
    map.centerAndZoom(new BMap.Point(113.170211,28.187604), 12);
    //取得开始节点
    function test(){
    var pStart = document.getElementById("a").value;
    //终点值
    var pEnd = new BMap.Point(113.170211,28.187604);
    //返回路线
    var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
    driving.search(pStart, pEnd);
    }
    </script>