<!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>
    <title></title>
    <script language="javascript">
        function test(obj)
        {
        var obj_input = document.getElementById("input_text");
            if (obj.checked)
            {
                obj_input.disabled = false;
                obj_input.focus();
            }
            else
            {
                obj_input.disabled = true;
            }
        }
    </script>
</head>
<body>
<input type="checkbox" value="0" id="cb_0" /><label for="cb_0">0</label><br /><input type="checkbox" value="1" id="cb_1" /><label for="cb_1">1</label><br /><input type="checkbox" id="cb_2" value="2" /><label for="cb_2">2</label><br /><input type="checkbox" id="cb_3" onclick="test(this)" value="-1" /><label for="cb_3">其他</label><input type="text" id="input_text" disabled="true" /> 
</body>
</html>
如果将此文本框激活,我如何获得该文本框中的值?

解决方案 »

  1.   

    document.getElementById("input_text").value;   
      

  2.   


    这个是javascript的吗?如果是php的话要怎么获取呢?
      

  3.   


    没有办法,只能js获取,然后传递给php
      

  4.   

    套入form表单 ,让表单提交 ,为你的input附上name属性 。
      

  5.   

    类似图片如下,checkbox的值可以通过循环获取。但是文本框的值我还是取不到。求解。页面代码及提交代码:<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <title></title>
        <script language="javascript">
            function test(obj)
            {
            var obj_input = document.getElementById("input_text");
                if (obj.checked)
                {
                    obj_input.disabled = false;
                    obj_input.focus();
                }
                else
                {
                    obj_input.disabled = true;
                }
            }
        </script>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="receive.php"> 
    <table width="100%"><tr>
    <td>
    <input type="checkbox" name="checkbox[]" value="0" id="cb_0" /><label for="cb_0">0</label><br />
    <input type="checkbox" name="checkbox[]" value="1" id="cb_1" /><label for="cb_1">1</label><br />
    <input type="checkbox" name="checkbox[]" value="2" id="cb_2" /><label for="cb_2">2</label><br />
    <input type="checkbox" name="checkbox[]" value="-1" id="cb_3" onclick="test(this)" /><label for="cb_3">其他:</label><input type="text" id="input_text" disabled="true" /> 
    </td></tr>
    </table>
    <input type="submit" name="Submit" value="提交" /> </form>
    </body>
    </html>
    [/HTML][code=PHP]
    <?php
    for($i=0;$i<=count($checkbox);$i++) 

    if(!is_null($checkbox[$i])) 
    {
    $chechvalue.=$checkbox[$i];


    echo $chechvalue.'<br />';
    ?>
      

  6.   

    <input type="text" id="input_text" name="input_text" disabled="true" /> php代码: print_r($_POST);  //看到了什么
      

  7.   

    接收页面,var_dump($_POST)的结果:
    array(2) { ["checkbox"]=> array(1) { [0]=> string(2) "-1" } ["Submit"]=> string(4) "提交" }
      

  8.   

    同上 document.getElementById("input_text").value;
      

  9.   

    哦,原来是缺少name字段属性。明白了。这个input_text的值是只能放在外面单独获取,不能计入循环吧?
      

  10.   

    如果你的 $checkbox 获取的是checkbox的值。则不能计入循环。