我正在創建一個HTML5 Web表單。其中一個輸入是地理定位,它通過點擊按鈕來填充(它插入GPS座標)。由於此輸入必須是必需的且必須是隻讀的(我不希望用戶在其中寫入自定義數據),因此如何處理? HTML5不允許使用required
和readonly
(這是有道理的),但在我的情況下,我需要應用它。你知道任何解決方法嗎?一起使用必需屬性和只讀屬性
我在SO和Google上搜索和搜索了這些內容,但似乎都沒有解決方案。
這裏是我的代碼的一部分:
<form class="form-horizontal" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="form-group">
<label class="control-label col-xs-3" for="coord">GPS coordinates:*</label>
<div class="col-xs-4">
<input type="text" class="form-control" id="coord" name="coord" required placeholder="Please enable geolocation service">
</div>
<div class="col-xs-3">
<button type="button" onclick="getLocation()" class="btn btn-primary" id="locate" disabled>Locate me</button>
</div>
</div>
它的工作!謝謝。 – smartmouse