Javascript OnBlur 不工作

发布于 2024-10-21 05:04:47 字数 448 浏览 8 评论 0原文

我有一个默认情况下禁用的文本框... onclick 可以工作并使其能够输入,但是当我单击单选按钮时.. 它不会再次禁用文本框

有任何线索吗?

<input type="radio" name="group1" value="website" OnBlur="javascript:document.getElementById('websiteurl').disabled = true;" OnClick="javascript:document.getElementById('websiteurl').disabled = false;">
<input name="websiteurl" type="text" id="websiteurl" value="http://" size="50" disabled="true" />

预先感谢

I have a textbox which is disabled by default... the onclick works and enables it to be typed in, but when i click the radio button away.. it doesn't disable the textbox again

Any clues ?

<input type="radio" name="group1" value="website" OnBlur="javascript:document.getElementById('websiteurl').disabled = true;" OnClick="javascript:document.getElementById('websiteurl').disabled = false;">
<input name="websiteurl" type="text" id="websiteurl" value="http://" size="50" disabled="true" />

Thanks in advance

Lee

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

平定天下 2024-10-28 05:04:47

没有“启用”属性。您必须将禁用设置为“禁用”才能禁用输入,或删除属性“禁用”才能启用它。

禁用=“true”是错误的语法,应该禁用=“disabled”

There is no attribute "enabled". You would have to set disabled to "disabled" to disable an input, or remove the attribute "disabled" to enable it.

disabled="true" is the wrong syntax, it should be disabled="disabled"

我一向站在原地 2024-10-28 05:04:47

没有启用属性。您使用disabled并将其设置为truefalse

除此之外:

使用小写属性(否则它不是有效的 XHTML);无需在其前面放置 javascript:
此外,最好从 JavaScript 代码附加事件而不是内联它们。特别是如果您使用像 jQuery 这样的库,这非常简单:(

$('input[name=group1][value=website]').blur(function() {
    $('#websiteurl').attr('disabled', 'true');
}).click(function() {
    $('#websiteurl').removeAttr('disabled');
});

当然,#id 会比 input[name=group1][value=website] 更好选择器)

There is no attribute enabled. You use disabled and set it to true or false.

Besides that:

Use lowercase attributes (otherwise it's not valid XHTML); there's no need to put javascript: in front of it.
Additionally, it is better to attach events from JavaScript code instead of inlining them. Especially if you use a library like jQuery it's extremely easy:

$('input[name=group1][value=website]').blur(function() {
    $('#websiteurl').attr('disabled', 'true');
}).click(function() {
    $('#websiteurl').removeAttr('disabled');
});

(of course a #id would be much better instead of the input[name=group1][value=website] selector)

秋心╮凉 2024-10-28 05:04:47

将启用更改为禁用,它将起作用。

没有启用的属性。

Change enabled to disabled and it will work.

There is no enabled property.

你的他你的她 2024-10-28 05:04:47

不完全确定上下文,但是在这种情况下,复选框是否更适合禁用或启用文本框?

$('input[type="checkbox"]').click(function() {
    if (this.checked) {
        $('#websiteurl').removeAttr('disabled');
    }
    else {
        $('#websiteurl').attr('disabled', true);
    }
});

Not totally sure on the context, but wouldn't a checkbox be more appropriate in this situation to disable or enable a textbox?

$('input[type="checkbox"]').click(function() {
    if (this.checked) {
        $('#websiteurl').removeAttr('disabled');
    }
    else {
        $('#websiteurl').attr('disabled', true);
    }
});
眼中杀气 2024-10-28 05:04:47

尝试使用 disabled=true 而不是 enabled=false

Try disabled=true instead of enabled=false

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文