如何使用 jQuery Multifile 禁用元素?

发布于 2024-09-01 10:55:07 字数 387 浏览 4 评论 0原文

此代码没有按预期禁用我的元素

if(Multifile.n==0){
    $("#btnUpload").attr("disabled","disabled");
}

此代码没有按预期启用我的元素

$("#btnUpload").attr("disabled","");

我在 jQuery.MultiFile.js 中添加了这些行,位于我认为是的位置之后在 MultiFile 对象中添加和删除文件。据我所知, MultiFile.n 是一个计数器。

如何在列表中没有文件的情况下禁用btnUpload,并在至少有一个的情况下启用它。

This code does not disable my element as expected

if(Multifile.n==0){
    $("#btnUpload").attr("disabled","disabled");
}

This code does not enable my element as expected

$("#btnUpload").attr("disabled","");

I added these lines in jQuery.MultiFile.js after what I believe is the location where files are added and removed from the MultiFile object. As far as I can tell, MultiFile.n is a counter.

How can I disable btnUpload when there are no files in the list, and enable it as long as there is at least one.

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

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

发布评论

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

评论(1

—━☆沉默づ 2024-09-08 10:55:07

如果元素上有一个禁用属性,那么即使该属性为空,它也将始终被禁用。这是因为原始(SGML 变体)HTML 的属性没有这样的值,

<INPUT TYPE="text" DISABLED>

因此您必须删除该属性

$('#btnUpload').removeAttr('disabled');

If there is a disabled attribute on the element, it will always be disabled, even if the attribute is empty. This is because the original (SGML variant of) HTML had attributes without values like this

<INPUT TYPE="text" DISABLED>

So you have to remove the attribute

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