js関数数方法:
<script> <br>function getDefaultSelectedOption(selectId, valIfNull) {<br>var dom, selectId = selectId.replace(/^#/, ''), opts; <br>try { <br>opts = document.getElementById(selectId).getElementsByTagName('option'); <br>for (var i in opts) { <br>if (opts[i].defaultSelected) { <br>dom = opts[i]; <br>休憩; <br>} <br>} <br>} catch (e) { <br>} <br>return dom||valIfNull; <br>} <br></script>
デモ:
< ;本体>
function getDefaultSelectedOption(selectId, valIfNull) {
var dom, selectId = selectId.replace(/^#/, ''), opts;
try {
opts = document.getElementById(selectId).getElementsByTagName('option');
for (var i in opts) {
if (opts[i].defaultSelected) {
dom = opts[i];
休憩;
}
}
} catch (e) {
}
return dom||valIfNull;
}
document.getElementById('btn').onclick = function () {
alert((getDefaultSelectedOption('sel1', {})).value);
};