禁用负载分区不工作为什么? [英] Disable div on load is not working why?
问题描述
我想在加载时禁用div,然后点击按钮启用它。
或者换句话说,我想在用户点击时加载并加载它时,它会隐藏它。
首先,这是一种正确的策略在禁用模式下加载一个div然后启用它,或者我应该在加载后将它附加到body上?第二,这里是我的代码,我已经检查了许多类似的问题,我的浏览器是铬合金,但它不工作,我不知道你为什么可以帮助我通过这个?
< div class =test_disstyle =left:170px; top:128px; >
这是一个测试,看看
是否可以在加载时禁用它
< div> child< / div>
< / div>
$(document).load(function(e){//它是在加载还是准备好?
//.attr(disabled,disabled);都是不工作!
$('。test_dis')。attr('disabled',true);
});
谢谢
它不起作用,因为您无法禁用 div
元素。这只适用于表单元素。
以下元素支持disabled属性:BUTTON,INPUT ,
OPTGROUP,OPTION,SELECT和TEXTAREA。
对于禁用工作的元素,您应该设置HTML属性以便该元素在创建时已被禁用,而不是在创建元素后将其禁用。例如:
< input type =textname =Infodisabled =disabled/>
load
事件,所以你不能直接在HTML元素中做任何调整,你应该在 ready 事件中进行。
ready 事件发生在文档加载时,而
load
事件发生在页面上的所有内容(图像et.c.)也已加载。
I want to disable the div on load , then enable it on click of botton. Or on the other words i want to invisible it when it load and load it when user click.
Frist, is that a correct strategy to load a div in disable mode then enable it , or shall I append it to body after loading ?
Second, here is my code , I have checked many similar questions, my browser is chrome and yet it is not working, I dont know why can you help me through this ?
<div class="test_dis" style="left:170px; top:128px;" >
this is a test to see if
i can disable it on load or not
<div>child </div>
</div>
$(document).load(function(e) { // shall it be on Load or Ready ?
//.attr("disabled","disabled"); both are not working !
$('.test_dis').attr('disabled',true);
});
Thank you ,
It's not working because you can't disable a div
element. That only works for form elements.
"The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA."
For elements where disabling works, you should set the HTML attribute so that the element is disabled already when it's created, rather than disabling it after it is created. Example:
<input type="text" name="Info" disabled="disabled" />
The ready
event happens earlier than the load
event, so any adjustments that you can't do directly in the HTML elements, you should do in the ready
event. The ready
event happens when the document has loaded, while the load
event happens when all the content on the page (images et.c.) also has been loaded.
这篇关于禁用负载分区不工作为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!