<select> 沒有 readonly 屬性,disabled 會導致表單不提交該欄位值。
<span id="selectWrapper">
<select name="sjdwmc"><option value="1">選項一</option></select>
</span>
<script>
function makeSelectReadOnly(wrapperId) {
var wrapper = document.getElementById(wrapperId);
// 捕獲滑鼠事件,阻止聚焦
wrapper.onmouseover = function(){ this.setCapture(); };
wrapper.onmouseout = function(){ this.releaseCapture(); };
wrapper.onfocus = function(){ this.blur(); };
wrapper.onbeforeactivate = function(){ return false; }; // IE 專用
}
// 頁面載入啟用
window.onload = function(){ makeSelectReadOnly('selectWrapper'); };
</script>
<select name="city" disabled><option value="1" selected>台北</option></select>
<input type="hidden" name="city" value="1">
select[readonly] { pointer-events: none; background: #f5f5f5; }
$('#city').on('focus', function(){
var val = this.value;
setTimeout(() => { this.blur(); this.value = val; }, 0);
});
disabled 會從無障礙樹移除,需搭配 aria-readonly="true"。