JS 函数方法 :
复制代码代码如下:
<cript>
function getDefaultSelectedOption (selectId, valifnull) {
var Dom, selectId = selectId.replace (/ ^ # /, ''), opts;
essayer {
opts = document.getElementById (selectId) .getElementsByTagName ('option');
pour (var i en opts) {
if (opts [i] .defaultSelected) {
dom = opts [i];
casser;
}
}
} catch (e) {
}
return Dom || Valifnull;
}
</cript>
Démo:
复制代码代码如下:
<body>
<select id = "sel">
<Option Value = "1"> 1 </ Option>
<Option Value = "2" Selected = ""> 2 </ Option>
<Option Value = "3"> 3 </ Option>
</lect>
<Button id = "btn"> Tester </ Button>
<cript>
function getDefaultSelectedOption (selectId, valifnull) {
var Dom, selectId = selectId.replace (/ ^ # /, ''), opts;
essayer {
opts = document.getElementById (selectId) .getElementsByTagName ('option');
pour (var i en opts) {
if (opts [i] .defaultSelected) {
dom = opts [i];
casser;
}
}
} catch (e) {
}
return Dom || Valifnull;
}
</cript>
<cript>
document.getElementById ('btn'). onClick = function () {
alert ((getDefaultSelectedOption ('sel1', {})). valeur);
};
</cript>
</docy>
不知道还有没有更方便快捷的方法 , 曾尝试通过 jQuery 获取 $ ('# SEL Option [DefaultSelected]') , 可一直返回空。
各位园友 , 我要的是 Sélectionnez 控件初始化的值 , 非 Sélectionnez 当前选中的值 , 初始化的值不随 Sélectionnez 值改变 , 大家可以做一下 Demo , 当 Sélectionnez 值改变后 , 初始化的值是不会变的。