javascript 支持表单下拉列表的更改

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 支持表单下拉列表的更改相关的知识,希望对你有一定的参考价值。

/*	Task 1	*/
// In the builder form, the Dropdown values should be the ones the user is supposed to see
const dropdownValues = {
	  // On the left side of the colon is the field name the user sees, on the right side is the value that is saved on form submit
	  // To add other fields, follow the example: 
	  // "Visible value" : "Submitted value"
	  "INTO Glasgow Caledonian University" : "INTO Scotland at Glasgow Caledonian Uni",
  	"INTO London" : "intoLondon",
  	"INTO University of East Anglia" : "intoAnglia",
  	"Yes" : "Good"
}
$.each( dropdownValues, function(visibleText, submitText){
    $( "option:contains('" + visibleText + "')" ).val(submitText);
});



/*	Task 2	*/
// Leave all the options in the builder, then it will filter and hide on the live page the ones that are irrelevant
// Important: Below copy paste the options that SHOULD be visible in the dropdown
// All other options that are not in the list below, will be hidden on the live page
const UKuniversities = ["INTO London", "INTO Queen's University Belfast", "INTO University of East Anglia", "INTO University of Gloucestershire", "INTO Glasgow Caledonian University"];
function page_generator(inputName){
	if (window.__page_generator) { 
		return inputName; 
	} else {
		return base64_encode(inputName);
	}
}

$('select[name="' + page_generator("INTO Centre") + '"]').children().slice(1).each(function(){
	if(jQuery.inArray($(this).text(), UKuniversities) == -1) {
	    $(this).detach();
	} 
});

以上是关于javascript 支持表单下拉列表的更改的主要内容,如果未能解决你的问题,请参考以下文章

使用VBscript与网页上的表单进行交互并触发JavaScript事件

我想在更改主下拉菜单时构建更新表单然后更新第二个下拉列表

HTML 表单选择元素不允许更改

在 Javascript/JQuery 中选择单选选项时,是不是可以动态更改下拉列表的颜色或更改列表项的颜色?

如何创建多个从同一个数组中获取值的动态下拉列表,而无需更改 Javascript 中的其他下拉列表

使用 javascript 在下拉列表中保存值