我用ajax创建了一个弹出窗口,当重新加载带调用ajax的单选按钮时,我按下了双击以正确显示弹出响应。
按启用地址时,单选按钮会通过ajax重新加载。我要按2次。
我的代码示例:
http://codepen.io/alexd2/pen/xZOOBN
步骤:
理想的是按1次。
我的代码示例
<div id="my">
<form action="" name="frm" id="frm">
<div class="select-radio">
<input type="radio" name="shipping_method" id="s_method_puntoshipping_free"> Free
<input type="radio" name="shipping_method" id="s_method_puntoshipping_puntoshipping" data-mfp-src="#map-pd"> Punto
</div>
</form>
<script>
jQuery.noConflict();
jQuery(function(){
jQuery( document ).on("click","#s_method_puntoshipping_puntoshipping", function(){
jQuery("#s_method_puntoshipping_puntoshipping").magnificPopup({
callbacks: {
open: function() {
//INIT
//CLOSE
}
,
beforeClose: function() {
var location=jQuery("#selectedLocationPunto").val();
var cp=jQuery("#selectedPostalCodePunto").val();
var address = jQuery("#selectedAddressPunto").val();
jQuery("#billing\\:city").val(location);
jQuery("#billing\\:postcode").val(cp);
jQuery("#billing\\:street1").val(address);
jQuery("#s_method_puntoshipping_puntoshipping").prop("checked", true);
}
}
});
});
jQuery( document ).on( "click", "a#lnk-select", function() {
setTimeout(function(){
jQuery(".mfp-close").click();
}, 500);
});
});
</script>
</div>
<div id="address" class="check-address">
<input type="checkbox" name="chck" id="chck"> Enabled address
</div>
<div class="inputs">
<input type="text" id="billing:city" value="">
<input type="text" id="billing:postcode" value="">
<input type="text" id="billing:street1" value="">
</div>
<div id="map-pd" class="mfp-hide" style="padding: 40px; background: #FFF; margin: 0 auto; position: relative; width: 20%; min-height: 200px;">
<div id="puntoWidget">
<input type="text" id="postalcode" name="postalcode" value="6635"><br/>
<input type="text" id="address" name="address" value="Street Jhon Snow"><br/>
<input type="text" id="location" name="location" value="N/A"><br/>
<button name="setvalue" id="setvalue">Set</button>
</div>
<input id="selectedPostalCodePunto" type="hidden">
<input id="selectedAddressPunto" type="hidden">
<input id="selectedLocationPunto" type="hidden">
</div>
<script>
jQuery.noConflict();
jQuery(function(){
jQuery("#setvalue").on('click', function(){
jQuery("#selectedPostalCodePunto").val(jQuery("#postalcode").val());
jQuery("#selectedAddressPunto").val(jQuery("#address").val());
jQuery("#selectedLocationPunto").val(jQuery("#location").val());
setTimeout(function(){
jQuery(".mfp-close").click();
}, 500);
});
jQuery("#chck").on('change', function(){
jQuery.ajax({
url: "http://fiddle.jshell.net/alexd2/yd5jegm9/show/",
cache:false,
beforeSend: function( xhr ) {
jQuery( "#my" ).html('<img src="ajax-loader.gif">');
}
})
.done(function( data ) {
jQuery( "#my" ).html( data );
});
});
});
</script>
错误在哪里?