我正在尝试访问组合框的选定选项的文本属性。以下代码是我到目前为止所达到的位置,但我无法识别代码中的错误。
<!DOCTYPE html>
<html >
<head>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<style type="text/css">
table,td
{
border: 1px solid black;
}
td
{
height:30px;
vertical-align:center;
padding:15px;
}
.tableClass
{
border:1px;
border: 1px solid black;
}
</style>
<script src='dojo/dojo.js' data-dojo-config='parseOnLoad: true'></script>
<script>
//require(["dojo/parser", "dijit/form/FilteringSelect", "dojo/store/Memory"]);
</script>
<script type="text/javascript">
dojo.require("dijit.form.ComboBox");
function alterEntries()
{
//alert("in");
document.getElementById('overlayName').value = dijit.byId('stateSelect').value;
dojo.style("description", {
display:"block",
});
dojo.style("overlayName", {
display:"block",
});
}
function submitEntries(ovlName,overlayDescription)
{
var textOfOvl = getSelectedText(ovlName);
alert("overlayName " + ovlName + " overlayDescription " + overlayDescription);
}
function getSelectedText(elementId)
{
var elt = document.getElementById(elementId);
if (elt.selectedIndex == -1)
{
alert("null");
return null;
}
return elt.options[elt.selectedIndex].text;
}
</script>
</head>
<body class="claro">
<select id="stateSelect" data-dojo-type="dijit.form.ComboBox">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
</select>
<input name="overlayName" type="text" value="overlayName" id="overlayName" style="display:none">
<textarea name="description" cols="50" rows="3" id="description" style="display:none"></textarea>
<p>
<button onclick="alterEntries();">EDIT</button>
<button onclick="submitEntries(document.getElementById('overlayName').value,document.getElementById('description').value);">SUBMIT</button>
</p>
</body>
</html>
我正在努力弄清楚出了什么问题。有人可以帮帮我吗。非常感谢!