使用javascript动态创建选择器值,我尝试创建以下代码:
function generateButton() {
var Period = "Period";
function add(selText, selID) {
var sel = document.getElementById(selID);
console.log(sel);
var selValue = sel.value;
return selText + selValue;
}
var x = add("Period: ", Period + "---");
}
<select id="Period" name="Period" data-val-required="The Period field is required." data-val="true">
<button type="submit" onclick="generateButton()">Generate</button>
但是获得sel值的null。我在这里错过了什么吗?