简体   繁体   English

在页面加载之前禁用下拉菜单-Javascript

[英]Disable Dropdown until Page has Loaded - Javascript

I am having an issue with a couple of my pages. 我的几个页面出现问题。

Essentially I am using JQuery to display followup questions using SlideDown. 本质上,我使用JQuery使用SlideDown显示后续问题。 In addition to this, after clicking the Q2 radio button, we make a JSON request to get the drop down values for Q3. 除此之外,单击Q2单选按钮后,我们发出JSON请求以获取Q3的下拉值。

However if you select the drop down value before the page has completed loading, on selecting the radio on Q2, Q1 dropdown clears back to empty. 但是,如果在页面加载完成之前选择下拉值,则在选择Q2上的单选按钮时,Q1下拉列表将清除为空。

I have tried moving all the javascript code to the top to no avail. 我尝试将所有JavaScript代码移到顶部都无济于事。 This is not a problem if the page has completed loading however. 但是,如果页面已完成加载,则这不是问题。

Is there a way to disable or hide the dropdown until the page has fully loaded? 在页面完全加载之前,是否有办法禁用或隐藏下拉菜单?

Cheers 干杯

Ryan 瑞安

Working DEMO 工作演示

Initially set disabled property in HTML: 最初在HTML中设置Disabled属性:

<select id="dropdown" style="width:200px;" disabled>
    <option value="feedback" name="aft_qst">After Quest</option>
    <option value="feedback" name="aft_exm">After Exam</option>
</select>

on dom ready use following to remove disabled property. 在dom准备使用后,请删除以下禁用的属性。

$(document).ready(function(){
    $("#dropdown").prop("disabled", false);  
});

You should use the ready function of jQuery, what you put inside will be executed when the DOM is fullly loaded 您应该使用jQuery的ready函数,当DOM完全加载时,将执行您放入的内容

$(function() {
  // Enable your dropdown
});

more info: 更多信息:

http://api.jquery.com/ready/ http://api.jquery.com/ready/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM