私はJavaScriptでいくつかの選択を設定しています。それらのいくつかについては、選択オプションが同じであるため、1つのオプションを作成してから、関連するすべての選択を設定することを考えました。
これが私が実際に行っている方法です:
var option = document.createElement('option');
option.text = 'please select a journal';
option.value ='NULL';
try
{
selectSection.add(option, null); // standards compliant; doesn't work in IE
}
catch(ex)
{
selectSection.add(option); // IE only
}
var option = document.createElement('option');
option.text = 'please select a journal';
option.value ='NULL';
try
{
selectSpecialIssue.add(option, null); // standards compliant; doesn't work in IE
}
catch(ex)
{
selectSpecialIssue.add(option); // IE only
}
var option = document.createElement('option');
option.text = 'please select a journal';
option.value ='NULL';
try
{
selectVolume.add(option, null); // standards compliant; doesn't work in IE
}
catch(ex)
{
selectVolume.add(option); // IE only
}
.............ETC................
私は1つのオプションのみを作成しようとしました(オプションは同じです)そしてそれらの選択を入力します:
var option = document.createElement('option');
option.text = 'please select a journal';
option.value ='NULL';
try
{
selectSection.add(option, null);
selectSpecialIssue.add(option, null);
selectVolume.add(option, null);
}
catch(ex)
{
selectSection.add(option);
selectSpecialIssue.add(option);
selectVolume.add(option);
}
ここでのコードははるかにわかりやすく、理解しやすいですが、問題は、最後の選択(selectVolume)のみが入力されていることです。理由はわかりません。