我使用Foundation6透露編碼彈出窗體。我遇到的JavaScript問題我跟蹤到的可能與jQuery.js/Foundation.js事件綁定或處理有關。Foundation6透露彈出式窗體字段不需要的焦點丟失(在jQuery事件?)
當我點擊文本字段(或任何其他字段)在顯示窗口中的域獲得焦點,然後顯示窗口快速隱藏,並再次顯示和場已失去焦點。揭開窗口也改變了它在屏幕上的位置。只有訪問文本字段的方法是使用tab鍵。
的index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.4/foundation.css"/>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.4/foundation.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="app.js"></script>
</head>
<body>
<section class="container clearfix">
<h3>Click button to open modal and test focus lost problem:</h3>
<p><a href="modalform.html" class="button" data-open="newFormModal" data-showloading="1">Test focus modal form</a></p>
</section>
<div class="reveal" id="newFormModal" data-reveal data-close-on-click><section class="modalContent"></section><button class="close-button" data-close aria-label="Close reveal" type="button"><i class="fi-x"></i></button></div>
</body>
</html>
modalform.html
<h3 class="modalheader">PopupForm</h3>
<form method="post" accept-charset="utf-8" class="ajaxModal" data-showloading="1" data-open="newFormModal" action="/test/modalform3">
<div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
<div class="input text"><label for="ga-20x28">Product 1 qty:</label><input type="text" name="ProductQuantities[726][value]" id="ga-20x28" value="0" /></div> <input type="hidden" name="ProductQuantities[726][name]" value="GA 20x28" />
<div class="input text"><label for="ga-30x40">Product 2 qty:</label><input type="text" name="ProductQuantities[727][value]" id="ga-30x40" value="0" /></div> <input type="hidden" name="ProductQuantities[727][name]" value="GA 30x40" />
<div class="input text"><label for="ga-50x70">Product 3 qty:</label><input type="text" name="ProductQuantities[728][value]" id="ga-50x70" value="0" /></div> <input type="hidden" name="ProductQuantities[728][name]" value="GA 50x70" />
<button type="submit">Next</button>
</form>
<button data-close="" class="refreshId" type="submit">Close</button>
app.js:
$(document).ready(function() {
$(document).foundation();
$("body").on("click", "a[data-open]", function(e) {
e.preventDefault();
var $this = $(this);
var modalName = $this.data("open");
var $modal = $("#" + modalName);
var $target = $modal.children(".modalContent");
var requestUri = $(this).attr('href');
var requestData;
var method;
if($this.attr('data-request')) {
requestData = $(this).data("request");
method = 'POST';
} else {
requestData = "";
method = 'GET';
}
// Load content:
var request = $.ajax({
url: requestUri,
method: method,
data: requestData,
dataType: "html",
timeout: 60000
});
request.done(function(response) {
$target.html(response);
$target.foundation();
});
});
});
在這裏,您可以測試行爲(在我的瀏覽器至少火狐& Chrome):[
http://codepen.io/repeat_spacer/pen/bBRZKd][1]
。從按鈕打開顯示彈出窗口並嘗試更改任何文本字段的值。用鼠標點擊進入該區域是不可能的。
希望有人能指出我的問題或如何繼續追蹤它。
UPDATE:
我打掃modalform.html代碼(有一些Ajax揭示承載新的形式的東西,我有阿賈克斯負載下一個表格)。所以現在「加載下一個表格」功能不起作用,但另一方面,「焦點丟失」行爲消失了。
modalform_updated.html:
<h3 class="modalheader">PopupForm</h3>
<form method="post" accept-charset="utf-8" class="ajaxModal" action="submitmodal.php">
<div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
<div class="input text"><label for="p1qty">Product 1 qty:</label><input type="text" name="ProductQuantities[p1][value]" id="p1qty" value="0" /></div>
<div class="input text"><label for="p2qty">Product 2 qty:</label><input type="text" name="ProductQuantities[p2][value]" id="p2qty" value="0" /></div>
<div class="input text"><label for="p3qty">Product 3 qty:</label><input type="text" name="ProductQuantities[p3][value]" id="p3qty" value="0" /></div>
<button type="submit">Submit</button>
</form>
<button data-close="" class="refreshId" type="submit">Close</button>
更新codepen: http://codepen.io/repeat_spacer/pen/MbrYvj
更新2:
這裏是形式爲什麼我的數據開放(基礎顯示開放屬性)的原因屬性。這似乎是導致行爲的原因,當點擊表單中的字段時,會觸發Foundation Open事件。所以快速修復會將其過濾出一些骯髒的方式。
這裏是小提琴手與多彈出功能,我想有:http://codepen.io/repeat_spacer/pen/JbMdPm(第一彈出模態AJAX負載下一個彈出同一內容模式)
投票的原因是什麼? –
可能因爲你的問題沒有遵循http://stackoverflow.com/help/how-to-ask well – GillesC
@GillesC那麼現在好嗎? –