微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

来看看怎么通过a标签打开一个对话框

前言:也许这是一个很简单的动作,你似乎觉得这没什么,的确,在我完成了这个功能后,我觉得也很简单。

这里写图片描述

弹出框后面是一个table,点击单元格中的修改连接,就可以弹出对话框,并且能够将数据传递到页面前端。

页面

<a href="${ctx}/project/editProjectReback/${deal_item.id}" target="dialog" width="600">修改</a>

注意:

  1. 参数target
  2. width

js封装

//dialogs
	$("a[target=dialog]", $p).each(function(){
		$(this).click(function(event){
			var $this = $(this);
			var title = $this.attr("title") || $this.text();
			var options = {};
			var w = $this.attr("width");
			var h = $this.attr("height");
			if (w) options.width = w;
			if (h) options.height = h;
			options.title = title;
			options.contentType = "ajax";
			options.showButton = eval($this.attr("showButton") || "false");
			options.showCancel = eval($this.attr("showCancel") || "false");
			options.showOk = eval($this.attr("showOk") || "false");
			options.type = "wee";
			options.onopen = eval($this.attr("onopen") ||  function() {});
			options.Boxid = "pop_ajax_dialog";

			var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
			YUNM.debug(url);
			if (!url.isFinishedTm()) {
				$.showErr($this.attr("warn") || YUNM.msg("alertSelectMsg"));
				return false;
			}
			$.weeBoxs.open(url, options);
			return false;
		});

注意:

  1. 此处仍然借用了DWZ的代码,通过将a标签上的参数传递给weeBox弹出框。
  2. url,用来使weeBox内部通过ajax请求发送到服务端。

页面初始化时

让以上代码执行以下就好

weeBox内部

else if (self.options.contentType == "ajax") {
				self.ajaxurl = self._content;
				self.setContent('<div class="dialog-loading"></div>');
				self.show();

				$.ajax({
					type : "post",
					url : self.ajaxurl,
					success : function(data) {
						self._content = data;
						self.setContent(self._content);
						self.onopen();
						self.focus();
						if (self.options.position == 'center') {
							self.setCenterPosition();
						}
					},
					error : YUNM.ajaxError
				})
			} 

注意:这里使用ajax请求获取到服务端数据

jfinal

	@Before(DealsInterceptor.class)
	public void editProjectReback() {
	
		if (dealItem != null) {
			setAttr("deal_item", dealItem);
			
			render("add_reback.jsp");
		}
	}

render到对应的页面,并且将参数“deal_item”传递到页面上。

add_reback.jsp

<textarea class="form-control required" rows="3" placeholder="报内容" name="description">${deal_item.description}</textarea>

结语:这串处理对我的整个项目有了很大的启示,接下来,我也将要对我原来的项目做法进行一些修改

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐