如何获取某个div里面的一个input的值(input在这个div里面是唯一的id)

解决方案 »

  1.   

    取input的value,document.getElementById(id).value;
      

  2.   

    input的ID在整个页面肯定也是唯一的,用document.getElementById(id).value就可以了
      

  3.   

    LZ说的应该不是ID吧,把代码贴出来看一下
      

  4.   

    id必须在整个网页中都唯一。如果非要按照你说的那么写的话,这么写就可以document.getElementById("yourDivId").getElementById("yourInputId")
      

  5.   

    取input的value,document.getElementById(id).value;或者$("#id").val();   就算不是唯一的也会取出第一个
      

  6.   

    用document.getElementById(id).value就可以了
      

  7.   

    谢谢大家了,
     其实只要不是服务器端的控件,id是可以重复的.
     比如这样是完全可以的!
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <div id="div1"><input id="aa" /></div>
                <div id="div2"><input id="aa" /></div>
            </div>
        </form>
    </body>
    </html>
      

  8.   


    工作上我当天下午就处理了,每次往一个div里面插入div块时,都先把插入的div里面的input的id给替换成唯一的!
    只是觉得好奇,看id相同,能不能处理!
      楼上还没有可用的答案!
      

  9.   


        <div>
            <div id="divA">
                <input type="text" id="text1" value="text 1"></div>
            <div id="divB">
                <input type="text" id="text1" value="text 2"></div>
        </div>
        <input type=button value="Click" onclick="alert(document.getElementById('divA').getElementsByTagName('input')[0].value);" />
      

  10.   

    这就不管你input的id了,取第一个。或者:        function getValue() {
                var inputs = document.getElementById('divA').getElementsByTagName('input');
                for (var i = 0, l = inputs.length; i < l; i++) {
                    if (inputs[i].id == "text1") {
                        alert(inputs[i].value);
                        break;
                    }
                }
            }