jWiard 基于JQuery的強(qiáng)大的向?qū)Э丶榻B
我就不貼我現(xiàn)在做項(xiàng)目的代碼,我直接把作者的示例搬過來,因?yàn)楦膭?dòng)不大,只要做點(diǎn)修改,就能很好的滿足我們自己的需求。
原文地址 猛點(diǎn)這里下載
作者官網(wǎng) 不過是英文的,英語好的話 可以看原文,生怕我表達(dá)錯(cuò)誤。
不知道童鞋們?cè)谄綍r(shí)的開發(fā)用到用向?qū)介_發(fā)這種方式?jīng)]有?有人問 什么是向?qū)介_發(fā)呢?其實(shí),很簡單,就是讓用戶完成一個(gè)步驟,然后點(diǎn)擊下一步,完成一個(gè)步驟就點(diǎn)擊下一步,這樣 按照我?guī)煾傅膩碚f,可以很好的提升用戶體驗(yàn)。
OK,廢話不說了,先來一個(gè)最簡單的例子:
例子1:
1.1當(dāng)然咯,既然是JQuery 就少不了需要引用JQuery庫吧。在上面就能下到相關(guān)的類庫。
JQuery Class and Style
<!-- jquery ui theme -->
<link rel="stylesheet" href="/path/to/jquery-ui.css" />
<!-- required CSS basics -->
<link rel="stylesheet" href="/path/to/jWizard.base.css" />
<!-- duh -->
<script type="text/javascript" src="/path/to/jquery.js"></script>
<!-- at least the widget factory -->
<script type="text/javascript" src="/path/to/jquery-ui.js"></script>
<!-- and the plugin itself -->
<script type="text/javascript" src="/path/to/jWizard.min.js"></script>
1.2 然后就開始寫 HTML代碼了,也很簡單。
HTML Code
<form id="wizard-form" class="jWizard">
<fieldset>
<legend>Beginning</legend>
<p>Are you sure you want to begin? Press "Next" to proceed?</p>
</fieldset>
<fieldset>
<legend>Middle</legend>
<p>Are you sure you want to?</p>
<p>You can still go back. Or press "Next" again to confirm.</p>
</fieldset>
<fieldset>
<legend>End</legend>
<p>Done, click "Finish" to end</p>
</fieldset>
</form>
<!-- Can also just be divs with title attributes -->
<div id="wizard-div" class="jWizard">
<div title="Beginning">
<p>Are you sure you want to begin? Press "Next" to proceed?</p>
</div>
<div title="Middle">
<p>Are you sure you want to?</p>
<p>You can still go back. Or press "Next" again to confirm.</p>
</div>
<div title="End">
<p>Done, click "Finish" to end</p>
</div>
</div>
你可以在上面的HTML代碼了 進(jìn)行添加相關(guān)的div,不過 可別忘記了給最外面的賦上title值哦。
1.3 js開始調(diào)用。
JS Call
$(".jWizard").jWizard({
menuEnable: true,
counter: {
enable: true,
progressbar: true
},
effects: { enable: true }
});
OK, 到此為止,上面的基本步驟就實(shí)現(xiàn)了,效果如下:
示例 2:給next添加事件
在我現(xiàn)在做的第一個(gè)版本里,剛開始比如有上傳文件,驗(yàn)證文件等等操作,很二的直接在頁面放了一個(gè)button,然后觸發(fā)它的javascript代碼。這樣做可以滿足基本功能的需求,可是也非常嚴(yán)重的損害了用戶的體驗(yàn)。因?yàn)?,現(xiàn)在的用戶非常的懶,能少做一點(diǎn)事情,它是絕對(duì)不會(huì)多做的。所以,如果你放一個(gè)button,用戶不想去點(diǎn)擊,然后就點(diǎn)擊next了,那么就得不到需要的用戶,就會(huì)報(bào)錯(cuò)。
因此,我們可以把一些操作都集成到Next中去,那這樣子就灰?;页5姆奖懔耍翼撁嬉沧兊幕页;页5恼麧嵈蠓健?
其余代碼可以基本不變,現(xiàn)在我主要講一下js里面的事件機(jī)制,代碼如下:
var $w = $("#events-test");
$w.validate({ errorClass: "ui-state-error-text" });
$w
.jWizard({
buttons: {
cancelType: "reset", // 點(diǎn)擊”Cancel“按鈕的時(shí)候 觸發(fā)的動(dòng)作,比如我在項(xiàng)目中,是跳到第一頁 重新開始。
finishType: "submit" // 在最后一步點(diǎn)擊”finish“的時(shí)候,出發(fā)的動(dòng)作,也就是提交。
},
// 點(diǎn)擊”Cancel“按鈕的時(shí)候 觸發(fā)的動(dòng)作,比如我在項(xiàng)目中,是跳到第一頁 重新開始。
cancel: function(event, ui) {
$w.jWizard("firstStep");
}, // 點(diǎn)擊previous的時(shí)候觸發(fā)的動(dòng)作。比如在我項(xiàng)目中,因?yàn)楫?dāng)把所有的郵件都發(fā)送完畢的時(shí)候,就不能讓用戶上一頁了,所以我要把上一頁的功能給進(jìn)禁止掉。很簡單,如下;
previous: function(event, ui) {
// if(ui.currentStepIndex==7){return false;} 就可以了。7 指的是你的div的順序數(shù)字,從0開始,哈這個(gè)會(huì)數(shù)吧。
},
next: function(event, ui) {
// 這里同理哦,就是控制下一頁的情況,也是上面一樣。比如,在我項(xiàng)目中,有一個(gè)上傳數(shù)據(jù)的,要是沒有就不能讓它上傳。這種情況 你可以先設(shè)定一個(gè)bool值,然后,
if(fileUploadComplete){ $.get("@Url.Action("VerificationSchema", "Home")", // 這里學(xué)習(xí)MVC的童鞋們應(yīng)該很熟悉 其實(shí)也就是在action home 下面的方法 VerificationSchema function (data) { // 獲取成功后返回的數(shù)據(jù) var newData = eval(data); // 因?yàn)橛玫膉son 所以用eval 進(jìn)行轉(zhuǎn)換 schemaVerification=newData.HasErrors; if(newData.HasErrors) { var listing1 = document.getElementById("listing1"); listing1.innerHTML = "<font color='red' size='20px'>Congruations.Please go on.</font>"; } else { document.getElementById("ErrorNotification").innerHTML="Sorry.Your Schema wrong,please check it."; var listing1 = document.getElementById("listing1"); listing1.innerHTML = newData.Result; } },"json");} else { //這里主要是當(dāng)沒有選擇數(shù)據(jù)的時(shí)候 進(jìn)行提示 alert("Please firstly Upload the Excel File you need"); return false; } break; },
finish: function(event, ui) {
alert("Thank you!");
}
})
/** The bindings below are event handlers, they will all be executed before proceeding to the callback */
/** ui = {
type: "previous|next|first|last|manual",
currentStepIndex: [int],
nextStepIndex: [int]
}; */
// This event handler is specifically used for form validation
.bind("jwizardchangestep", function (event, ui) {
// "manual" is always triggered by the user, never jWizard itself
if (ui.type !== "manual") {
var $currentStep = $w.find(".jw-step:eq(" + ui.currentStepIndex + ")"),
$inputs = $currentStep.find("input:text");
/** I am assuming you have `jquery.validate.js` running in this callback */
if ($inputs.length > 0 && !$inputs.valid()) {
$currentStep.find("label.error").effect("highlight");
return false;
}
}
})
// This event handler is for handling custom navigation through the wizard
.bind("jwizardchangestep", function (event, ui) {
// "manual" is always triggered by the user, never jWizard itself
if (ui.type !== "manual") {
// 這里其實(shí)是比較重要的,因?yàn)檫@里就是選擇對(duì)應(yīng)div的實(shí)現(xiàn)方式的,你只需要把相應(yīng)模塊的javascript代碼集成到這里就可以了。
switch (ui.currentStepIndex) {
// on the first step, the user must agree to the terms and conditions
case 0:
if ($("#agree").is(":not(:checked)")) {
// use this effect to give the user feedback
$("#agree").parent().effect("pulsate");
return false;
}
break;
// on the 3rd step, (zero-index) the username being filled means we are skipping the openid step
case 2:
if ($("#username").val() != "") {
// by setting this value on the event object, I am telling jWizard to override the nextStepIndex
event.nextStepIndex = 4;
// you must at least call event.preventDefault(); in order for this to work
return false;
}
break;
}
}
// by using nextStepIndex, we can intercept the user when they are *about to start* on a particular step
switch (ui.nextStepIndex) {
// in this case, I am displaying a summary on the last step of the wizard
case 4:
var oFormValues = {
name: $("#name").val(),
email: $("#email").val(),
username: $("#username").val(),
openid: undefined
};
$("#summary-name").children("td").text(oFormValues.name);
$("#summary-email").children("td").text(oFormValues.email);
if (oFormValues.username != "") {
$("#summary-username").show().children("td").text(oFormValues.username);
$("#summary-openid").hide().children("td").text("");
} else {
var $openid = $w.find("input:radio:checked[name=openid]");
oFormValues.openid = ($openid.length === 1) ? $openid.val() : $("#openid-other").val();
$("#summary-username").hide().children("td").text("");
$("#summary-openid").show().children("td").text(oFormValues.openid);
}
break;
}
});
// if the user clicks the openid link on step 3, (zero-index) cause the wizard to jump to the openid step
$("#openid").click(function () {
$w.jWizard("changeStep", 3);
return false;
});
// if an openid radio button is checked, blank out the `other` textbox
$w.find("input:radio[name=openid]").change(function (event) {
$("#openid-other").val("");
});
// if the `other` openid textbox is used, blank out the radio buttons
$("#openid-other").change(function (event) {
if (this.value != "") {
$w.find("input:radio[name=openid]").removeAttr("checked");
}
});
sum,我的搜狗怎么突然就沒有用了。
算了 以上就是我的一點(diǎn)點(diǎn)經(jīng)驗(yàn),就不說了,吃飯時(shí)間到了,如果有需要的童鞋在做開發(fā)的時(shí)候,如果遇到問題,可以進(jìn)行共同討論,呵呵 共同進(jìn)步嘛。
具體效果在這里 。
- datePicker——日期選擇控件(with jquery)
- Javascript jquery css 寫的簡單進(jìn)度條控件
- 基于jQuery的日期選擇控件
- 基于jquery的讓頁面控件不可用的實(shí)現(xiàn)代碼
- asp.net+jquery滾動(dòng)滾動(dòng)條加載數(shù)據(jù)的下拉控件
- jQuery選中select控件 無法設(shè)置selected的解決方法
- 基于jQuery的實(shí)現(xiàn)簡單的分頁控件
- 使用jquery與圖片美化checkbox和radio控件的代碼(打包下載)
- 基于jQuery的獲得各種控件Value的方法
- JQuery里面的幾種選擇器 查找滿足條件的元素$("#控件ID")
- 基于jquery跨瀏覽器顯示的file上傳控件
- jquery獲取tr中控件值并操作tr實(shí)現(xiàn)思路
- jquery設(shè)置控件位置的方法
- .net mvc頁面UI之Jquery博客日歷控件實(shí)現(xiàn)代碼
- jquery 日期控件datepicker屬性詳細(xì)解析
- Jquery獲得控件值的三種方法總結(jié)
- jquery日歷控件實(shí)現(xiàn)方法分享
- JQuery EasyUI 日期控件如何控制日期選擇區(qū)間
- jquery+javascript編寫國籍控件
相關(guān)文章
jQuery ajax 當(dāng)async為false時(shí)解決同步操作失敗的問題
這篇文章主要介紹了 jQuery ajax 當(dāng)async為false時(shí)解決同步操作失敗的問題的相關(guān)資料,需要的朋友可以參考下2016-11-11jQuery頭像裁剪工具jcrop用法實(shí)例(附演示與demo源碼下載)
這篇文章主要介紹了jQuery頭像裁剪工具jcrop用法,結(jié)合實(shí)例形式分析了jQuery頭像裁剪工具jquery.jcrop.js具體使用技巧,并附帶了完整的demo源碼供讀者下載參考,需要的朋友可以參考下2016-01-01Jquery Ajax Error 調(diào)試錯(cuò)誤的技巧
jquery在程序開發(fā)ajax應(yīng)用程序時(shí)提高了效率,減少了需要兼容性的問題,當(dāng)我們?cè)赼jax項(xiàng)目中,遇到ajax異步獲取數(shù)據(jù)出錯(cuò)該怎么解決呢,我們可以通過捕捉error事件來獲取出錯(cuò)的信息,本文給大家介紹jquery ajax error調(diào)試錯(cuò)誤的技巧,感興趣的朋友一起學(xué)習(xí)吧2015-11-11使用PHP+JQuery+Ajax分頁的實(shí)現(xiàn)
本篇文章小編將為大家介紹,使用PHP+JQuery+Ajax分頁的實(shí)現(xiàn)。需要的朋友參考下2013-04-04jquery插件jquery.dragscale.js實(shí)現(xiàn)拖拽改變?cè)卮笮〉姆椒?附demo源碼下載)
這篇文章主要介紹了jquery插件jquery.dragscale.js實(shí)現(xiàn)拖拽改變?cè)卮笮〉姆椒?涉及jquery針對(duì)鼠標(biāo)事件的響應(yīng)及頁面元素動(dòng)態(tài)操作的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-02-02jQuery仿360導(dǎo)航頁圖標(biāo)拖動(dòng)排序效果代碼分享
這篇文章主要為大家詳細(xì)介紹了360導(dǎo)航頁圖標(biāo)拖動(dòng)排序效果代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-08-08