JS : :
复制代码代码如下:
<script>
function getDefaultelectedOption (selectId, Valifnull) {
var dom, selectid = selectid.replace (/^#/, ''), opts;
intentar {
opts = document.getElementById (selectId) .getElementsBytagName ('opción');
para (var i en opts) {
if (opts [i] .defaultelected) {
dom = opts [i];
romper;
}
}
} catch (e) {
}
return DOM || Valifnull;
}
</script>
Manifestación:
复制代码代码如下:
<Body>
<select id = "sel">
<opción valor = "1"> 1 </opción>
<opción valor = "2" selected = ""> 2 </ppection>
<opción valor = "3"> 3 </opción>
</select>
<botón id = "btn"> test </boton>
<script>
function getDefaultelectedOption (selectId, Valifnull) {
var dom, selectid = selectid.replace (/^#/, ''), opts;
intentar {
opts = document.getElementById (selectId) .getElementsBytagName ('opción');
para (var i en opts) {
if (opts [i] .defaultelected) {
dom = opts [i];
romper;
}
}
} catch (e) {
}
return DOM || Valifnull;
}
</script>
<script>
document.getElementById ('btn'). onClick = function () {
alerta ((getDefaultelectEnectOption ('Sel1', {})). Value);
};
</script>
</body>
不知道还有没有更方便快捷的方法 , 曾尝试通过 jQuery 获取 $ ('#sel opción [defaultSelected]') 可一直返回空。 可一直返回空。
各位园友 , 我要的是 Seleccione 控件初始化的值 , 非 Seleccione 当前选中的值 , 初始化的值不随 Seleccione 值改变 , 大家可以做一下 Demo , 当 Seleccione 值改变后 初始化的值是不会变的。 初始化的值是不会变的。