当前位置:首页编程相关 → 正文

单选框控制文本框是否为只读属性

文章来源:网络收集  文章录入:天边  发布时间:2006-09-27  【放大字体 缩小字体】


用两个单选按钮,点击第一个的时候文本框可以输入值,当选择第二个单选框的时候,文本框不能输入,为只读属性,应该怎么做啊?高手帮忙!

<input name="txt" type="text" id="txt" value="欢迎来到54编程区">
<input name="radiobutton" type="radio" value="radiobutton" checked onClick="document.getElementById('txt').disabled=false;">
可输入  
<input type="radio" name="radiobutton" value="radiobutton" onClick="document.getElementById('txt').disabled=true;">
不能输入

可是在单选框里我已经用onclick了,也不能用两个啊。。怎么弄啊。。

你直接在你的 onclick 后面加上我 上面 onclick 的语句啊

<body onLoad="ab='address'" >
<script language=JavaScript >
function radiobutton_Click(a)
{
   
        for(var as=0;as<document.f.radiobutton.length;as )
    {
              if(document.f.radiobutton[as].checked)
         {
              ab=document.f.radiobutton[as].value;
              document.f.txt.value=a     
              }     
    }
}
</script>

欢迎来到电脑故障网(www.dngz.net)

  <table width=746 border=0 cellpadding=0 cellspacing=0>
    <tr valign=top><td width=13></td><td width="720" height=62> <form name=f action="User_sale.asp" method="post">
          <div align="center">
            <input type="hidden" name="ddl_areainfo">
                        <input name="txt" type="text" size="30" value="请添加地址或选择地址">
            <input type="button" name="Submit"  onclick="window.open(ab '.htm','','')" value="选择">
                        <input name="提交" type=submit value=搜索>
            <input name="submit" type=button value=发布求购信息 onClick="window.location.href='Release_purchase.asp'" >
            <br>
            <br>
            <input type="radio" name="radiobutton" onClick="radiobutton_Click('请添加地址或选择地址');" value="address" checked>
            地址
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择学区');" value="district">

本文来自电脑故障网(www.dngz.net)


            学区
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公交线路');" value="Bus_route">
            公交线路
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公园广场');" value="Parkplaza">
            公园广场
                                    <br>
          </div>
     </form></td></tr>
                </table>
你看看应该怎么弄啊?

要在我原有的功能上添加,我弄了好长时间了,都加不上。。要求只选择地址的时候文本框才可以输入,,选其他的都是只读的。。

<body onLoad="ab='address'" >
<script language=JavaScript >
function radiobutton_Click(a)
{
   
     for(var as=0;as<document.f.radiobutton.length;as )
    {
              if(document.f.radiobutton[as].checked)
         {
              ab=document.f.radiobutton[as].value;
              document.f.txt.value=a         

欢迎来到电脑故障网(www.dngz.net)

              }         
    }
}
</script>
  <table width=887 border=0 cellpadding=0 cellspacing=0>
    <tr valign=top><td width=13></td><td width="874" height=62> <form name=f action="User_sale.asp" method="post">
          <div align="center">
            <input type="hidden" name="ddl_areainfo">
                        <input name="txt" type="text" size="30" value="请添加地址或选择地址">
            <input type="button" name="Submit"  onclick="window.open(ab '.htm','','')" value="选择">
                        <input name="提交" type=submit value=搜索>
            <input name="submit" type=button value=发布求购信息 onClick="window.location.href='Release_purchase.asp'" >
            <br>
            <br>
            <input type="radio" name="radiobutton" onClick="radiobutton_Click('请添加地址或选择地址');" value="address" checked>
            地址
www.dngz.net

            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择学区');" value="district">
            学区
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公交线路');" value="Bus_route">
            公交线路
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公园广场');" value="Parkplaza">
            公园广场
                               
<input name="radiobutton" type="radio" value="radiobutton" checked onClick="document.getElementById('txt').disabled=false;">
可输入  
<input type="radio" name="radiobutton" value="radiobutton" onClick="document.getElementById('txt').disabled=true;">
不能输入
          </div>
     </form></td></tr>
                </table>

我晕。。。
我是说在点 地址 单选框的时候让txt文本框变成能写的,当点其他三个的时候,txt文本框为只读就是readonly
我是这个意思,你误会我的意思了。。。

而且还要不改变我原有的功能。。我的这几个功能都是必须有的。。

<body onLoad="ab='address'" > 电脑故障网(www.dngz.net)版权所有
<script language=JavaScript >
function radiobutton_Click(a)
{
   
     for(var as=0;as<document.f.radiobutton.length;as )
    {
              if(document.f.radiobutton[as].checked)
         {
              ab=document.f.radiobutton[as].value;
              document.f.txt.value=a         
              }         
    }
}
</script>
  <table width=887 border=0 cellpadding=0 cellspacing=0>
    <tr valign=top><td width=13></td><td width="874" height=62> <form name=f action="User_sale.asp" method="post">
     <div align="center">
            <input type="hidden" name="ddl_areainfo">
                        <input name="txt" type="text" size="30" value="请添加地址或选择地址">
            <input type="button" name="Submit"  onclick="window.open(ab '.htm','','')" value="选择">
                        <input name="提交" type=submit value=搜索> 欢迎来到电脑故障网(www.dngz.net)
            <input name="submit" type=button value=发布求购信息 onClick="window.location.href='Release_purchase.asp'" >
            <br>
            <br>
            <input type="radio" name="radiobutton" onClick="radiobutton_Click('请添加地址或选择地址');document.getElementById('txt').disabled=false;" value="address" checked>
            地址
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择学区');document.getElementById('txt').disabled=true;" value="district">
            学区
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公交线路');document.getElementById('txt').disabled=true;" value="Bus_route">
            公交线路
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公园广场');document.getElementById('txt').disabled=true;" value="Parkplaza">
            公园广场
          </div>

电脑故障网(www.dngz.net)为您排除一切电脑故障


     </form></td></tr>
                </table>

这样不好用。。。你没试试嘛。。。这种方法我刚才试了,不好用。。

那你就在具体说清楚点啊

就是在运行的时候点哪个单选在文本框里都显示提示语。。而且要选地址的时候又能在文本框还添加又能点选择

<body onLoad="ab='address'" >
<script language=JavaScript >
function radiobutton_Click(a)
{
   
     for(var as=0;as<document.f.radiobutton.length;as )
    {
              if(document.f.radiobutton[as].checked)
         {
              ab=document.f.radiobutton[as].value;
              document.f.txt.value=a         
              }         
    }
}
</script>
  <table width=887 border=0 cellpadding=0 cellspacing=0>
    <tr valign=top><td width=13></td><td width="874" height=62> <form name=f action="User_sale.asp" method="post">
     <div align="center">
            <input type="hidden" name="ddl_areainfo">
                        <input name="txt" type="text" size="30" value="请添加地址或选择地址" disabled> www.dngz.net
            <input type="button" name="Submit"  onclick="window.open(ab '.htm','','')" value="选择">
                        <input name="提交" type=submit value=搜索>
            <input name="submit" type=button value=发布求购信息 onClick="window.location.href='Release_purchase.asp'" >
            <br>
            <br>
            <input type="radio" name="radiobutton" onClick="radiobutton_Click('请添加地址或选择地址');document.getElementById('txt').disabled=false;" value="address">
            地址
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择学区');document.getElementById('txt').disabled=true;" value="district">
            学区
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公交线路');document.getElementById('txt').disabled=true;" value="Bus_route">
            公交线路
            <input type="radio" name="radiobutton"  onClick="radiobutton_Click('请选择公园广场');document.getElementById('txt').disabled=true;" value="Parkplaza"> 欢迎来到电脑故障网(www.dngz.net)
            公园广场
     </div>
     </form></td></tr>
                </table>

只读属性应该设置为readonly吧,readonly = true;,disabled指的是显示问题.再说如果想将其文本框值加入数据库的话,用disabled也不用啊!!!!
我感觉应该用readonly!
An静,你说对不?

那应该怎么往里加啊。。

<script>
        function aaaa()
        {
                if(document.form1.radioname.checked)
                {
                        document.form1.textfield.readOnly = true;
                        document.form1.textfield.value = 1;
                }
        }
</script>
<form name = "form1">
        <input type = "text" name = "textfield">
        <input type = "radio" name = "radioname" onclick = "aaaa();">select
</form>
将这个例子拷贝过去,运行下,你就会明白了!!!!


只读属性应该设置为readonly吧,readonly = true;,disabled指的是显示问题.再说如果想将其文本框值加入数据库的话,用disabled也不用啊!!!!

电脑故障网(www.dngz.net)


我感觉应该用readonly!
An静,你说对不?
:victory: 呵呵

的确,disabled设为True后,表单中此文本框的值便不会被传输了,readonly不存在些问题.

打印本文  返回顶部  加入收藏  关闭窗口