62,046
社区成员
发帖
与我相关
我的任务
分享
(function ($) {
//class为.wBox_close为关闭
$.fn.wBox = function (options) {
var defaults = {
wBoxURL: "wbox/",
opacity: 0.5, //背景透明度
callBack: null,
noTitle: false,
show: false,
timeout: 0,
target: null,
requestType: "iframe", //iframe,ajax,img
title: "wBox Title",
drag: true,
iframeWH: {//iframe 设置高宽
width: 800,
height: 400
},
html: ''//wBox内容
}, _this = this;
this.YQ = $.extend(defaults, options);
var wBoxHtml = '<div id="wBox"><div class="wBox_popup"><table><tbody><tr><td class="wBox_tl"/><td class="wBox_b"/><td class="wBox_tr"/></tr><tr><td class="wBox_b"><div style="width:10px;"> </div></td><td><div class="wBox_body">' + (_this.YQ.noTitle ? '' : '<table class="wBox_title"><tr><td class="wBox_dragTitle"><div class="wBox_itemTitle">' + _this.YQ.title + '</div></td><td width="20px" title="关闭"><div class="wBox_close"></div></td></tr></table> ') +
'<div class="wBox_content" id="wBoxContent"></div></div></td><td class="wBox_b"><div style="width:10px;"> </div></td></tr><tr><td class="wBox_bl"/><td class="wBox_b"/><td class="wBox_br"/></tr></tbody></table></div></div>', B = null, C = null, $win = $(window), $t = $(this); //B背景,C内容jquery div
this.showBox = function (what) {
$("#wBox_overlay").remove();
$("#wBox").remove();
B = $("<div id='wBox_overlay' class='wBox_hide'></div>").hide().addClass('wBox_overlayBG').css('opacity', _this.YQ.opacity).dblclick(function () {
_this.close();
}).appendTo('body').fadeIn(300);
C = $(wBoxHtml).appendTo('body');
handleClick(what);
}
/*
* 处理点击
* @param {string} what
*/
function handleClick(what) {
var con = C.find("#wBoxContent");
if (_this.YQ.requestType && $.inArray(_this.YQ.requestType, ['iframe', 'ajax', 'img']) != -1) {
con.html("<div class='wBox_load'><div id='wBox_loading'><img src='" + _this.YQ.wBoxURL + "loading.gif' /></div></div>");
if (_this.YQ.requestType === "img") {
var img = $("<img />");
img.attr("src", _this.YQ.target);
img.load(function () {
img.appendTo(con.empty());
setPosition();
});
}
else
if (_this.YQ.requestType === "ajax") {
$.get(_this.YQ.target, function (data) {
con.html(data);
C.find('.wBox_close').click(_this.close);
setPosition();
})
}
else {
_this.YQ.target = what;
ifr = $("<iframe name='wBoxIframe' style='width:" + _this.YQ.iframeWH.width + "px;height:" + _this.YQ.iframeWH.height + "px;' scrolling='auto' frameborder='0' src='" + _this.YQ.target + "'></iframe>");
ifr.appendTo(con.empty());
ifr.load(function () {
try {
$it = $(this).contents();
$it.find('.wBox_close').click(_this.close);
fH = $it.height(); //iframe height
fW = $it.width();
w = $win;
newW = Math.min(w.width() - 40, fW);
newH = w.height() - 25 - (_this.YQ.noTitle ? 0 : 30);
newH = Math.min(newH, fH);
if (!newH)
return;
var lt = calPosition(newW);
C.css({
left: lt[0],
top: lt[1]
});
$(this).css({
height: newH,
width: newW
});
}
catch (e) {
}
});
}
}
else
if (_this.YQ.target) {
$(_this.YQ.target).clone(true).show().appendTo(con.empty());
}
else
if (_this.YQ.html) {
con.html(_this.YQ.html);
}
else {
$t.clone(true).show().appendTo(con.empty());
}
afterHandleClick();
}
/*
* 处理点击之后的处理
*/
function afterHandleClick() {
setPosition();
C.show().find('.wBox_close').click(_this.close).hover(function () {
$(this).addClass("on");
}, function () {
$(this).removeClass("on");
});
$(document).unbind('keydown.wBox').bind('keydown.wBox', function (e) {
if (e.keyCode === 27)
_this.close();
return true
});
typeof _this.YQ.callBack === 'function' ? _this.YQ.callBack() : null;
!_this.YQ.noTitle && _this.YQ.drag ? drag() : null;
if (_this.YQ.timeout) {
setTimeout(_this.close, _this.YQ.timeout);
}
}
/*
* 设置wBox的位置
*/
function setPosition() {
if (!C) {
return false;
}
var width = C.width(), lt = calPosition(width);
C.css({
left: lt[0],
top: lt[1]
});
var $h = $("body").height(), $wh = $win.height(), $hh = $("html").height();
$h = Math.max($h, $wh);
B.height($h).width($win.width())
}
/*
* 计算wBox的位置
* @param {number} w 宽度
*/
function calPosition(w) {
l = ($win.width() - w) / 2;
t = $win.scrollTop() + $win.height() / 9;
return [l, t];
}
/*
* 拖拽函数drag
*/
function drag() {
var dx, dy, moveout;
var T = C.find('.wBox_dragTitle').css('cursor', 'move');
T.bind("selectstart", function () {
return false;
});
T.mousedown(function (e) {
dx = e.clientX - parseInt(C.css("left"));
dy = e.clientY - parseInt(C.css("top"));
C.mousemove(move).mouseout(out).css('opacity', 0.8);
T.mouseup(up);
});
/*
* 移动改变生活
* @param {Object} e 事件
*/
function move(e) {
moveout = false;
if (e.clientX - dx < 0) {
l = 0;
}
else
if (e.clientX - dx > $win.width() - C.width()) {
l = $win.width() - C.width();
}
else {
l = e.clientX - dx
}
C.css({
left: l,
top: e.clientY - dy
});
}
/*
* 你已经out啦!
* @param {Object} e 事件
*/
function out(e) {
moveout = true;
setTimeout(function () {
moveout && up(e);
}, 10);
}
/*
* 放弃
* @param {Object} e事件
*/
function up(e) {
C.unbind("mousemove", move).unbind("mouseout", out).css('opacity', 1);
T.unbind("mouseup", up);
}
}
/*
* 关闭弹出框就是移除还原
*/
this.close = function close() {
if (C) {
B.remove();
C.stop().fadeOut(300, function () {
C.remove();
})
}
}
/*
* 触发click事件
*/
$win.resize(function () {
setPosition();
});
_this.YQ.show ? _this.showBox() : $t.click(function () {
var what = $(this).attr("href");
_this.showBox(what);
return false;
});
return this;
};
})(jQuery);
这是WBOX.JS
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
strsql = "insert into ABC(单位名称)values(" + t + ");
bool z = Das.ExecSql(strsql);
if (z)
{
这里如何调用WBOX.JS 的关闭弹出层的函数
}
else
{
Response.Write("<script>alert('单位信息新增失败!');</script>");
}
}
function click1()
{
parent.document.getElementById("XXX").style.display = "none";
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "click1", "<script> document.getElementById('click1').click(); </script>");
<a id="tempclick" class="wBox_close" href="#"></a>
<asp:ImageButton/>
Page.ClientScript.RegisterStartupScript(this.GetType(), "tempclick", "<script> document.getElementById('tempclick').click(); </script>");
/// <summary>
/// JSEngine 在后台运行js的解释器返回值
/// </summary>
public class JSEngine
{
//初始化加载程序的字符串;
public static readonly String _jsString = @"class theEval{ public function Eval(str:String):String {return eval(str)}}";
public static readonly String _jsClassName = @"theEval";
public static readonly String _jsMethodName = @"Eval";
//定义对象
public static object _evalObject = new object();
public static Type _evalType = new object().GetType();
//构造函数
static JSEngine()
{
CreatJSEngine(ref _evalObject, ref _evalType, _jsString, _jsClassName);
}
/// <summary>
/// 初始化引擎的方法
/// </summary>
/// </summary>
/// <param name="evalObject">指定一个 已存在的变量 保存 使用evalType的类型生成一个实例</param>
/// <param name="evalType">指定一个 已存在的变量 保存 生成的程序集中有指定名称的对象type</param>
/// <param name="jsString">指定用来生成程序集的代码文本</param>
/// <param name="jsClassName">指定用来进行调用的程序集中的类别名称</param>
private static void CreatJSEngine(ref object evalObject, ref Type evalType, string jsString, string jsClassName)
{
CodeDomProvider _provider = new JScriptCodeProvider();
CompilerParameters _parameters = new CompilerParameters();
_parameters.GenerateInMemory = true;
CompilerResults _result = _provider.CompileAssemblyFromSource(_parameters, jsString);
Assembly _assembly = _result.CompiledAssembly;
evalType = _assembly.GetType(jsClassName);
evalObject = Activator.CreateInstance(evalType);
}
/// <summary>
/// StringEval
/// </summary>
/// <param name="inp_JSString">传入一个表达式</param>
/// <returns>返回一个表达式的值</returns>
public static object StringEval(string inp_JSString)
{
return _evalType.InvokeMember(_jsMethodName, BindingFlags.InvokeMethod, null, _evalObject, new object[] { inp_JSString });
}
/// <summary>
/// StringEval
/// </summary>
/// <param name="inp_JSFunctionString">指定用来生成程序集的代码文本</param>
/// <param name="inp_JSFunctionClassName">指定用来进行调用的程序集中的类别名称</param>
/// <param name="inp_JSFunctionClassFuncName">指定用来进行调用的程序集中的类别中的函数的名称</param>
/// <param name="inp_ParameterObject">要传递到程序集中的变量对象数组,无参时使用 new object[0]</param>
/// <returns>返回函数调用的值</returns>
public static object StringEval(string inp_JSFunctionString, string inp_JSFunctionClassName, string inp_JSFunctionClassFuncName, object[] inp_ParameterObject)
{
object ClosureevalObject = null;
Type ClosureevalType = null;
CreatJSEngine(ref ClosureevalObject, ref ClosureevalType, inp_JSFunctionString, inp_JSFunctionClassName);
return ClosureevalType.InvokeMember(inp_JSFunctionClassFuncName, BindingFlags.InvokeMethod, null, ClosureevalObject, inp_ParameterObject);
}
/// <summary>
/// StringEval
/// </summary>
/// <param name="inp_JSString">传入一个表达式</param>
/// <param name="inp_theType">指定的要返回的值类型</param>
/// <returns>返回的值</returns>
public static object StringEval(string inp_JSString, Type inp_theType)
{
return Microsoft.JScript.Convert.Coerce(_evalType.InvokeMember(_jsMethodName, BindingFlags.InvokeMethod, null, _evalObject, new object[] { inp_JSString }), inp_theType);
}
}