简体   繁体   English

在javascript中提交表单后动态禁用下拉列表值

[英]Dynamically disable dropdown list value after form submission in javascript

I have a drop down list and I can dynamically disable the value that was selected before. 我有一个下拉列表,可以动态禁用之前选择的值。

But now I want the value to remain disabled even after form submission. 但是现在我希望该值即使在提交表单后也保持禁用状态。 (Each and every value that the user selected in the dropdown list should remain disabled on and after form submission ) That is even when a different user access the page the value should remain disabled(greye-out) (用户在下拉列表中选择的每个值在表单提交后均应保持禁用状态),即使其他用户访问该页面,该值也应保持禁用状态(灰色框)

 var $select = $("select"); $select.on("change", function() { var selected = []; $.each($select, function(index, select) { if (select.value !== "") { selected.push(select.value); } }); $("option").prop("disabled", false); for (var index in selected) { $('option[value="'+selected[index]+'"]').prop("disabled", true); } 
 <select class="selectDate" name="category1" id="dateSlot" onchange="showData()" required=""> <option value="" disabled selected>---Select Date---</option> <option value="Tuesday, 6 February 2018">Tuesday, 6 February 2018</option> <option value="Wednesday, 7 February 2018">Tuesday, 7 February 2018</option> <option value="Thursday, 8 February 2018">Tuesday, 8 February 2018</option> </select> 

JavaScript runs in the context of the current page and is completely removed from memory along with HTML and CSS when the browser navigates from one page to another after form submission. JavaScript在当前页面的上下文中运行,并且在提交表单后浏览器从一页导航到另一页时,JavaScript会与HTML和CSS一起从内存中完全删除。 And the same applies to other users visiting the page. 这同样适用于访问该页面的其他用户。

You have persist the state to some storage (eg the database, or the local storage in the browser) in before the form submission, and read it before rendering the page to change the behavior accordingly. 在提交表单之前,您已将状态持久保存到某个存储(例如数据库或浏览器中的本地存储)中,并在呈现页面以进行相应更改之前对其进行了读取。

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

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