<input>元素外面套了一个<p>元素,如果用javascript获取这个p元素?

解决方案 »

  1.   


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    </head>
    <body>
    <p id="test">
    <input type="button" value="click" onclick="alert( this.parentNode.id )" />
    </p>
    </body>
    </html>
      

  2.   

    <html>
    <head>
    <title>Upload File</title>
    </head>
    <body>
    <form name="myForm" action="#" method="post">
    <label for="uploading_file"><strong>File Uploading:</strong></label>
    <p><input type="file" name="uploading_file" id="uploading_file"></p>
    <input type="button" value="-" onclick="decreasing_quantity()">
    <input type="text" name="quantity" maxlength="2" size="2" value="0""/>
    <input type="button" value="+" onclick="increasing_quantity()">
    <input type="submit" value="Submit Files">
    </form>
    </body>
    </html>
    那个<p>标签是在<form>里面的,如何在javascript里面通过DOM获取?
      

  3.   

    <html>
    <head>
    <title>Upload File</title>
    </head>
    <body>
    <form name="myForm" action="#" method="post">
    <label for="uploading_file"><strong>File Uploading:</strong></label>
    <p><input type="file" name="uploading_file" id="uploading_file"></p>
    <input type="button" value="-" onclick="decreasing_quantity()">
    <input type="text" name="quantity" maxlength="2" size="2" value="0""/>
    <input type="button" value="+" onclick="increasing_quantity()">
    <input type="submit" value="Submit Files">
    </form>
    <script>
    alert( document.getElementById('uploading_file').parentNode )
    </script>
    </body>
    </html>