這是Featherlight hide div on Close在羽之燈箱呼叫按鈕
我已經成功地解決了打開收藏夾問題的後續問題,但我已經添加了一個提交按鈕,我想呼籲(「提交」,函數)點擊時。
jQuery(document).ready(function() {
//Triggle when Preview Button is Clicked.
jQuery('.OpenLightBox').off('click').on('click', function(e) {
var pa_firstname= jQuery('input[name="pa-name_first"]').val();
var pa_lastname= jQuery('input[name="pa-name_last"]').val();
if (pa_firstname == null || pa_firstname == '') {
alert('Cannot be empty');
return false;
} else {
var content = '<div style="width: 200px; height: 300px;"><b>First Name in Ajax is </b>' + pa_firstname + ' <b>And Last Name in Ajax is ' + pa_lastname + '</b><button type="button" value="submit" class="LightBoxSubmit">Send Now</button><button type="button" value="back">Back</button></div>';
jQuery('#preview').html("");
jQuery('#preview').html(content);
jQuery.featherlight('#preview', {});
}
});
//Added function that detects click on .LightBoxSubmit which is a button in the lightbox to call a Submit event, which will trigger the function below.
jQuery(".LightBoxSubmit").off('click').on('click',function(e) {
document.getElementById("pd_test").submit();
alert('LightBoxSubmit Called');
});
//Once LightBoxSubmit button is clicked, this function is suppose to call so the Ajax (I removed the code for simplicity) event can process the $_POST data.
jQuery('#pd_test').on('submit',function(event) {
event.preventDefault();
alert('Called Submit')
var pa_firstname= jQuery('input[name="pa-[name_first]"]').val();
var pa_lastname= jQuery('input[name="pa-[name_last]"]').val();
if (pa_firstname == null || pa_firstname == '') {
alert('Cannot be empty');
} else
alert('Form Submitted');
console.log (pa_firstname);
});
return false;
})
問題:我無法提交按鈕,關閉燈箱,並提交表單。它不檢測on('click')事件。
如果可能的話,請創建一個小提琴。 –
是的,我更新了以前的小提琴,請看這個鏈接 https://jsfiddle.net/9vktzw88/3/ –