利用JQuery+EasyDrag 實(shí)現(xiàn)彈出可拖動(dòng)的Div,同時(shí)向Div傳值,然后返回Div選中的值
原來(lái)我們要寫(xiě)一個(gè)客戶端的特效,要寫(xiě)一兩天的JavaScript,然后再調(diào)試一兩天,才可以看見(jiàn)端倪?,F(xiàn)在我們只要使用JQuery和他的 plugin,就可以任意的實(shí)現(xiàn)我們腦海中的特效,感謝他們的編寫(xiě)者對(duì)人類的貢獻(xiàn)(一百個(gè)西紅柿砸過(guò)來(lái)。。。。。。。。。。。。。。)。
我今天實(shí)現(xiàn)的需求是一個(gè)需要從列表頁(yè)面中選擇要導(dǎo)出到word中的列,然后在將選中列的內(nèi)容導(dǎo)出到word中,同時(shí)為了增加通用性,列的個(gè)數(shù)不是固定的,也就是說(shuō)這張表格可能是4列,也可能是5列,待選擇的列數(shù)目不固定。例如:有下面的一張表格,然后我們要打印除薪水外的其他列?! ?/P>
姓名 |
年齡 |
性別 |
薪水 |
張三 | 19 | 男 | 10000 |
張三 | 19 | 男 | 10000 |
張三 | 19 | 男 | 10000 |
我的設(shè)計(jì)是先用后臺(tái)代碼循環(huán)這個(gè)表格的表頭,組成下面的字符串
1-Name--2-Age--3-Sex--4-Salary,將這個(gè)字符串存儲(chǔ)在hiddenfield中,然后由JavaScript讀取,動(dòng)態(tài)在彈出Div中添加checkbox對(duì)應(yīng)的html,
然后在選擇之后將選擇的值組成對(duì)應(yīng)的字符串,例如:選擇Name、Age、Sex,就組成,1-Name--2-Age--3Sex,存放在另外的一個(gè)hiddenfield中,在后臺(tái)代碼讀取這個(gè)選中的字符串,將表格中相應(yīng)的列導(dǎo)出到word中。
同時(shí)為了使這個(gè)彈出頁(yè)面可以拖動(dòng),使用了EasyDrag jQuery Plugin,可以從http://fromvega.com/wordpress/2007/07/14/easydrag-jquery-plugin/下載。
這個(gè)插件很好用,也很簡(jiǎn)單,
實(shí)現(xiàn)拖動(dòng)效果.
$(document).ready( function()
{
$("#divPanel").easydrag();
}
);
Html 代碼
<div id="divPanel" style="width:300px;height:300px;background:white;border:1px solid #000000;position:absolute;left:5px;top:50px" >
<div id="divTitle" style="width:100%;height:25px;background:lavender">
Title
</div>
<div style="width:100%">
</div>
</div>
EasyDrag還可以指定可拖動(dòng)的區(qū)域,比如只能通過(guò)標(biāo)題拖動(dòng)整個(gè)div,我們JS可以這樣寫(xiě)
$(document).ready ( function()
{
$("#divPanel").easydrag();
$("#divPanel").setHandler("divTitle");
}
);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<style type="text/css">
.pop-box {
z-index: 9999;
margin-bottom:3px;
display:none;
position:absolute;
background:#ffffff;
border:solid 1px #6e8bde;
}
.pop-box h4{
color:#ffffff;
cursor:default;
height:18px;
font-size:14px;
font-weight:bold;
text-align:left;
padding-left:8px;
padding-top:4px;
padding-bottom:2px;
}
.pop-box-body{
clear:both;
margin:4px;
padding:2px;
}
</style>
<script type="text/javascript" src="script/jquery.js">
</script>
<script type="text/javascript" src="script/jquery.easydrag.js"></script>
<script typ="text/javascript">
$(document).ready(function(){
var text = "1-Name--2-Age--3-Sex--4-Salary";
var tokenGroup = new Array();
tokenGroup = text.split("--");
$(".optionDiv").append("<fieldset class='fieldset1'><legend class='legend1'>閫夋嫨瑕佸鍑哄埌Word涓殑鍒?/legend></fieldset>");
var obj = new Object();
for (obj in tokenGroup) {
//alert(obj);
//alert(Number(obj));
var index = Number(obj) + 1;
//alert(index);
var token = new Object();
token.value = tokenGroup[obj].split("-")[0];
token.text = tokenGroup[obj].split("-")[1];
//alert("value:"+token.value+" text:"+token.text);
if (index == 1) {
$(".legend1").after("<input id='Checkbox" +
index.toString() +
"' value='" +
token.value +
"' type='checkbox' /><label for='Checkbox" +
index.toString() +
"'>" +
token.text +
"</label><br>");
}
else {
$(".fieldset1").append("<input id='Checkbox" +
index.toString() +
"' value='" +
token.value +
"' type='checkbox' /><label for='Checkbox" +
index.toString() +
"'>" +
token.text +
"</label><br>");
}
}
});
$(document).ready(function(){
$(".btnSelect").click(function(){
var select = "";
$(".fieldset1 input").each(function(i){
if (this.checked) {
if (select == "")
select = (i + 1).toString() + "-" + $(this).next().text();
else
select += "--" + (i + 1).toString() + "-" + $(this).next().text();
}
});
$(".selected").val(select);
});
$("#btnClose").click(function(){
var select = "";
$(".fieldset1 input").each(function(i){
if (this.checked) {
if (select == "")
select = (i + 1).toString() + "-" + $(this).next().text();
else
select += "--" + (i + 1).toString() + "-" + $(this).next().text();
}
});
$(".selected").val(select);
});
});
$(document).ready(function(){
$(".pop-box").easydrag();
});
function loadText(){
var text = $(".hiddenfield1").val();
var tokenGroup = new Array();
tokenGroup = text.split("--");
$(".pop-box-body").html("");
$(".pop-box-body").append("<fieldset class='fieldset1'><legend class='legend1'>閫夋嫨瑕佸鍑哄埌Word涓殑鍒?/legend></fieldset>");
var obj = new Object();
for (obj in tokenGroup) {
//alert(obj);
//alert(Number(obj));
var index = Number(obj) + 1;
//alert(index);
var token = new Object();
token.value = tokenGroup[obj].split("-")[0];
token.text = tokenGroup[obj].split("-")[1];
//alert("value:"+token.value+" text:"+token.text);
if (index == 1) {
$(".legend1").after("<input id='Checkbox" +
index.toString() +
"' value='" +
token.value +
"' type='checkbox' /><label for='Checkbox" +
index.toString() +
"'>" +
token.text +
"</label><br>");
}
else {
$(".fieldset1").append("<input id='Checkbox" +
index.toString() +
"' value='" +
token.value +
"' type='checkbox' /><label for='Checkbox" +
index.toString() +
"'>" +
token.text +
"</label><br>");
}
}
}
function popupDiv(div_id){
var div_obj=$("#"+div_id);
var windowWidth=document.documentElement.clientWidth;
var windowHeight=document.documentElement.clientHeight;
var popupHeight=div_obj.height();
var popupWidth=div_obj.width();
$("<div id='mask'></div>").addClass("mask").width(windowWidth*0.99)
.height(windowHeight*0.99).click(function(){
hideDiv(div_id);
}).appendTo("body").fadeIn(200);
div_obj.css({"position":"absolute"})
.animate({left:windowWidth/2-popupWidth/2,top:windowHeight/2-popupHeight/2,opacity:"show"},"show");
loadText();
}
function hideDiv(div_id){
$("#mask").remove();
$("#"+div_id).animate({left:0,top:0,opacity:"hide"},"slow");
}
</script>
</head>
<body>
<h1>New Web Project Page</h1>
<input class="hiddenfield1" type="hidden" value="1-Name--2-Age--3-Sex--4-Salary">
<input type="button" id="btnPopup" name="btnPopup" onclick="popupDiv('pop-div')" class="btnPopup" value="PopupDiv">
<div class="pop-box" style="width:300px" id="pop-div">
<h4>Title</h4>
<div class="pop-box-body">
<p></p>
</div>
<div class="butonPanel" style="text-align:right;">
<input value="Close" id="btnClose" onclick="hideDiv('pop-div');" type="button">
</div>
</div>
<!--<div class="optionDiv"></div>-->
<fieldset>
<legend>
</legend>
</fieldset>
<input type="button" id="button1" name="button1" class="btnSelect" value="selected">
<br>
<textarea class="selected" rows="5" cols="50">
</textarea>
</body>
</html>
源代碼下載
- jquery div拖動(dòng)效果示例代碼
- jQuery拖動(dòng)div、移動(dòng)div、彈出層實(shí)現(xiàn)原理及示例
- jQuery實(shí)現(xiàn)單擊彈出Div層窗口效果(可關(guān)閉可拖動(dòng))
- jQuery 可以拖動(dòng)的div實(shí)現(xiàn)代碼 腳本之家修正版
- jQuery實(shí)現(xiàn)DIV層淡入淡出拖動(dòng)特效的方法
- jquery拖動(dòng)改變div大小
- jQuery實(shí)現(xiàn)的鼠標(biāo)拖動(dòng)浮層功能示例【拖動(dòng)div等任何標(biāo)簽】
- jquery實(shí)現(xiàn)可拖動(dòng)DIV自定義保存到數(shù)據(jù)的實(shí)例
- jQuery實(shí)現(xiàn)Div拖動(dòng)+鍵盤(pán)控制綜合效果的方法
- jQuery動(dòng)態(tài)添加可拖動(dòng)元素完整實(shí)例(附demo源碼下載)
- jQuery拖動(dòng)元素并對(duì)元素進(jìn)行重新排序
- jquery實(shí)現(xiàn)兩個(gè)div中的元素相互拖動(dòng)的方法分析
相關(guān)文章
使用jquery獲取url及url參數(shù)的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇使用jquery獲取url及url參數(shù)的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06jQuery實(shí)現(xiàn)6位數(shù)字密碼輸入框
本文主要對(duì)jQuery實(shí)現(xiàn)6位數(shù)字密碼輸入框的大概思路、實(shí)現(xiàn)代碼進(jìn)行詳細(xì)介紹,具有一定的參考價(jià)值,需要的朋友一起來(lái)看下吧2016-12-12基于jQuery的固定表格頭部的代碼(IE6,7,8測(cè)試通過(guò))
目前只能算個(gè)不完整的腳本,不過(guò)一般的僅僅需要表頭凍結(jié)就可以使用了2010-05-05jQuery檢測(cè)鼠標(biāo)左鍵和右鍵點(diǎn)擊的方法
這篇文章主要介紹了jQuery檢測(cè)鼠標(biāo)左鍵和右鍵點(diǎn)擊的方法,涉及jQuery操作鼠標(biāo)事件的技巧,且針對(duì)IE瀏覽器具備良好的兼容性,需要的朋友可以參考下2015-03-03jQuery Animation實(shí)現(xiàn)CSS3動(dòng)畫(huà)示例介紹
jQuery Animation的工作原理是通過(guò)將元素的CSS樣式從一個(gè)狀態(tài)改變?yōu)榱硪粋€(gè)狀態(tài),下面以一個(gè)實(shí)例為大家詳細(xì)介紹下具體的實(shí)現(xiàn),感興趣的朋友可以參考下2013-08-08jQuery選擇沒(méi)有colspan屬性的td的代碼
為了試著用jQuery找出一個(gè)table中沒(méi)有colspan屬性的td,試了很多種方法,這個(gè)是最好的,記在這里,下次不要再忘了2010-07-07jQuery Validate驗(yàn)證框架詳解(推薦)
jQuery Validate 插件為表單提供了強(qiáng)大的驗(yàn)證功能,讓客戶端表單驗(yàn)證變得更簡(jiǎn)單,同時(shí)提供了大量的定制選項(xiàng),滿足應(yīng)用程序各種需求。有興趣的可以了解一下。2016-12-12jQuery實(shí)現(xiàn)返回頂部功能適合不支持js的瀏覽器
a標(biāo)簽指向錨點(diǎn)top,可以在頂部防止一個(gè)a name=top的錨點(diǎn),這樣在瀏覽器不支持js時(shí)也可以實(shí)現(xiàn)返回頂部的效果了2014-08-08