jQuery改变input状态

qq_28491007 2017-02-22 01:12:45

<input type="text" name="name" disabled>
<button type="button" >变更状态</button>

输入框默认是disabled,如何用jQuery或原生JS点击按钮后改变输入框的状态为可用,再次点击后禁用呢
...全文
197 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_28491007 2017-02-22
  • 打赏
  • 举报
回复
引用 5 楼 sinat_28984567 的回复:
[quote=引用 4 楼 qq_28491007 的回复:] 谷歌,火狐,IE都是这样的
好吧,我这里什么浏览器都对。
    <script>
        function changerstate()
        {
            if ($("#test").prop("disabled")) {
                $("#test").removeAttr("disabled");
            }
            else {
                $("#test").attr("disabled", true);
            }
        }
    </script>
</head>
<body>
    <input id="test" type="text" name="name" disabled/>
    <button type="button" onclick="changerstate()">变更状态</button>
</body>
要不你把你的代码贴出来看看 [/quote] 我在去检查下代码吧,多谢啦!
二月十六 2017-02-22
  • 打赏
  • 举报
回复
引用 4 楼 qq_28491007 的回复:
谷歌,火狐,IE都是这样的
好吧,我这里什么浏览器都对。
    <script>
        function changerstate()
        {
            if ($("#test").prop("disabled")) {
                $("#test").removeAttr("disabled");
            }
            else {
                $("#test").attr("disabled", true);
            }
        }
    </script>
</head>
<body>
    <input id="test" type="text" name="name" disabled/>
    <button type="button" onclick="changerstate()">变更状态</button>
</body>
要不你把你的代码贴出来看看
qq_28491007 2017-02-22
  • 打赏
  • 举报
回复
引用 3 楼 sinat_28984567 的回复:
对方 [quote=引用 2 楼 qq_28491007 的回复:] [quote=引用 1 楼 sinat_28984567 的回复:] 需要引用jq
    <script>
        function changerstate()
        {
            if ($("#test").prop("disabled")) {
                $("#test").removeAttr("disabled");
            }
            else {
                $("#test").attr("disabled", true);
            }
        }
    </script>
</head>
<body>
    <input id="test" type="text" name="name" disabled />
    <button type="button" onclick="changerstate()">变更状态</button>
</body>
第一次点击后输入框还是禁用状态啊,要多点击几次才正常[/quote] 不应该是这样,你多测试几次,还有你用的什么浏览器?[/quote] 谷歌,火狐,IE都是这样的
二月十六 2017-02-22
  • 打赏
  • 举报
回复
对方
引用 2 楼 qq_28491007 的回复:
[quote=引用 1 楼 sinat_28984567 的回复:] 需要引用jq
    <script>
        function changerstate()
        {
            if ($("#test").prop("disabled")) {
                $("#test").removeAttr("disabled");
            }
            else {
                $("#test").attr("disabled", true);
            }
        }
    </script>
</head>
<body>
    <input id="test" type="text" name="name" disabled />
    <button type="button" onclick="changerstate()">变更状态</button>
</body>
第一次点击后输入框还是禁用状态啊,要多点击几次才正常[/quote] 不应该是这样,你多测试几次,还有你用的什么浏览器?
qq_28491007 2017-02-22
  • 打赏
  • 举报
回复
引用 1 楼 sinat_28984567 的回复:
需要引用jq
    <script>
        function changerstate()
        {
            if ($("#test").prop("disabled")) {
                $("#test").removeAttr("disabled");
            }
            else {
                $("#test").attr("disabled", true);
            }
        }
    </script>
</head>
<body>
    <input id="test" type="text" name="name" disabled />
    <button type="button" onclick="changerstate()">变更状态</button>
</body>
第一次点击后输入框还是禁用状态啊,要多点击几次才正常
二月十六 2017-02-22
  • 打赏
  • 举报
回复
需要引用jq
    <script>
function changerstate()
{
if ($("#test").prop("disabled")) {
$("#test").removeAttr("disabled");
}
else {
$("#test").attr("disabled", true);
}
}
</script>
</head>
<body>
<input id="test" type="text" name="name" disabled />
<button type="button" onclick="changerstate()">变更状态</button>
</body>

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧