现在的位置: 首页 > 综合 > 正文

one of the two jquery Plug-in named “Confirm”

2013年08月29日 ⁄ 综合 ⁄ 共 1796字 ⁄ 字号 评论关闭

Now I will introduce two jquery Plug-in, they are confirm and help message. Maybe you will need them in some development situation.

Confirm

1What is confirm?

You can base on the name, guess what it is? 

It include two buttons which is "yes" and "no", you can choose one of the button to tell the system what will be do next.

2Scenarios  

If a user need to sign out from the system, then our system should check he or she really want to sign out, so we need confirm Plug-in

3、Introduce of confirm

It has five parameters: msg, this will display in the confirm view.

If you need set the confirm position you can pass parameters of 'x' and 'y'.

Above all, you also need two function name, to deal with two actions, choosing yes or no.

4、How to use

First, you need to load jQuery Frame, beause our confirm Plug-in is base on the jQuery Frame.

Second, you can use the Plug-in as other jquery frame, such as 

$("#id").confirm({"msg":"sure?"})

$(".class").confirm({"msg":"sure?", "okclick":"closeFunction", "cacelclick":"cancelFunction"})

5、Try it yourself

I will give a example below, you can use it like this.

<!--//index.html-->
<html>
	<head>
	<title>Test for confirm</title>
	<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="confirm.js"></script>
	</head>
	<body>
	<button id="delete_button">Delete</button>
	</body>
	<script>
	function deleteFunction(){
	console.log("good, you delete it success");
	}
	function cancelFunction(){
	console.log("you cancel the delete action");
	}
	$("#delete_button").click(function(){
		var offset = $(this).offset;
		$(this).confirm({
			"msg"    :  "are you make sure",
			"okclick"  : deleteFunction,
			"cacelclick" : cancelFunction,
			x : offset.top+20,
			y : offset.left
		});
	});
	</script>
</html>

<!--make sure that the confirm.js and jquery-1.6.2.min.js are in the same folder as index.html-->



You can download here, good luck for you







抱歉!评论已关闭.