1 在视图或html页面中输入如下脚本
<script type="text/javascript"> function openClient(arg) { try { var wsh = new ActiveXObject("UstcOriWebLabActivex.UstcOriWebLab"); window.open(arg); } catch (e) { alert("error"); window.open("/Download.html"); } }2 函数需要回调openClient
function payOrder(url, callback) { if (this.loadWaiting != false) { return; } this.setLoadWaiting(true); $.ajax({ cache: false, url: url, type: 'post', success: function (response) { if (response.isloing) { callback(response.arg); } location.href = response.url; }, complete: this.resetLoadWaiting, error: this.ajaxFailure }); }
3 调用payOrder
<div class="product-item" data-productid="@Model.Id"> <div class="picture"> <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title"> <img alt="@Model.DefaultPictureModel.AlternateText" src="@Model.DefaultPictureModel.ImageUrl" title="@Model.DefaultPictureModel.Title" /> </a> </div> <div class="details"> <h2 class="product-title"> <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })">@Model.Name</a> </h2> <div class="description"> @Html.Raw(Model.ShortDescription) </div> <div class="add-info"> <div class="prices"> @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice)) { <span class="price old-price">@Model.ProductPrice.OldPrice</span> } <span class="price actual-price">@Model.ProductPrice.Price</span> </div> <div class="buttons"> @if (!Model.ProductPrice.DisableBuyButton) { <input type="button" value="@T("ShoppingCart")" class="button-2 product-button" οnclick="AjaxCart.payOrder('@addtocartlink', openClient)" /> } </div> @Html.Widget("productbox_add_info") </div> </div> </div>
4 总结
注意:在payOrder中callback()是需要“()”,要不回调会不成功!结论:CallBack函数其实只是一个函数形参
意思是需要传一个函数对象给他,你自定义的payOrder本身就是一个函数对象,直接传进去就行了,不需要加上‘’,否则就变成一个字符串对象了