jWiard 基于JQuery的強大的向?qū)Э丶榻B
我就不貼我現(xiàn)在做項目的代碼,我直接把作者的示例搬過來,因為改動不大,只要做點修改,就能很好的滿足我們自己的需求。
原文地址 猛點這里下載
作者官網(wǎng) 不過是英文的,英語好的話 可以看原文,生怕我表達錯誤。
不知道童鞋們在平時的開發(fā)用到用向?qū)介_發(fā)這種方式?jīng)]有?有人問 什么是向?qū)介_發(fā)呢?其實,很簡單,就是讓用戶完成一個步驟,然后點擊下一步,完成一個步驟就點擊下一步,這樣 按照我?guī)煾傅膩碚f,可以很好的提升用戶體驗。
OK,廢話不說了,先來一個最簡單的例子:
例子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代碼了 進行添加相關(guān)的div,不過 可別忘記了給最外面的賦上title值哦。
1.3 js開始調(diào)用。
JS Call
$(".jWizard").jWizard({
menuEnable: true,
counter: {
enable: true,
progressbar: true
},
effects: { enable: true }
});
OK, 到此為止,上面的基本步驟就實現(xiàn)了,效果如下:
示例 2:給next添加事件
在我現(xiàn)在做的第一個版本里,剛開始比如有上傳文件,驗證文件等等操作,很二的直接在頁面放了一個button,然后觸發(fā)它的javascript代碼。這樣做可以滿足基本功能的需求,可是也非常嚴重的損害了用戶的體驗。因為,現(xiàn)在的用戶非常的懶,能少做一點事情,它是絕對不會多做的。所以,如果你放一個button,用戶不想去點擊,然后就點擊next了,那么就得不到需要的用戶,就會報錯。
因此,我們可以把一些操作都集成到Next中去,那這樣子就灰常灰常的方便了,而且頁面也變的灰?;页5恼麧嵈蠓?。
其余代碼可以基本不變,現(xiàn)在我主要講一下js里面的事件機制,代碼如下:
var $w = $("#events-test");
$w.validate({ errorClass: "ui-state-error-text" });
$w
.jWizard({
buttons: {
cancelType: "reset", // 點擊”Cancel“按鈕的時候 觸發(fā)的動作,比如我在項目中,是跳到第一頁 重新開始。
finishType: "submit" // 在最后一步點擊”finish“的時候,出發(fā)的動作,也就是提交。
},
// 點擊”Cancel“按鈕的時候 觸發(fā)的動作,比如我在項目中,是跳到第一頁 重新開始。
cancel: function(event, ui) {
$w.jWizard("firstStep");
}, // 點擊previous的時候觸發(fā)的動作。比如在我項目中,因為當(dāng)把所有的郵件都發(fā)送完畢的時候,就不能讓用戶上一頁了,所以我要把上一頁的功能給進禁止掉。很簡單,如下;
previous: function(event, ui) {
// if(ui.currentStepIndex==7){return false;} 就可以了。7 指的是你的div的順序數(shù)字,從0開始,哈這個會數(shù)吧。
},
next: function(event, ui) {
// 這里同理哦,就是控制下一頁的情況,也是上面一樣。比如,在我項目中,有一個上傳數(shù)據(jù)的,要是沒有就不能讓它上傳。這種情況 你可以先設(shè)定一個bool值,然后,
if(fileUploadComplete){ $.get("@Url.Action("VerificationSchema", "Home")", // 這里學(xué)習(xí)MVC的童鞋們應(yīng)該很熟悉 其實也就是在action home 下面的方法 VerificationSchema function (data) { // 獲取成功后返回的數(shù)據(jù) var newData = eval(data); // 因為用的json 所以用eval 進行轉(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ù)的時候 進行提示 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") {
// 這里其實是比較重要的,因為這里就是選擇對應(yīng)div的實現(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,我的搜狗怎么突然就沒有用了。
算了 以上就是我的一點點經(jīng)驗,就不說了,吃飯時間到了,如果有需要的童鞋在做開發(fā)的時候,如果遇到問題,可以進行共同討論,呵呵 共同進步嘛。
具體效果在這里 。
- datePicker——日期選擇控件(with jquery)
- Javascript jquery css 寫的簡單進度條控件
- 基于jQuery的日期選擇控件
- 基于jquery的讓頁面控件不可用的實現(xiàn)代碼
- asp.net+jquery滾動滾動條加載數(shù)據(jù)的下拉控件
- jQuery選中select控件 無法設(shè)置selected的解決方法
- 基于jQuery的實現(xiàn)簡單的分頁控件
- 使用jquery與圖片美化checkbox和radio控件的代碼(打包下載)
- 基于jQuery的獲得各種控件Value的方法
- JQuery里面的幾種選擇器 查找滿足條件的元素$("#控件ID")
- 基于jquery跨瀏覽器顯示的file上傳控件
- jquery獲取tr中控件值并操作tr實現(xiàn)思路
- jquery設(shè)置控件位置的方法
- .net mvc頁面UI之Jquery博客日歷控件實現(xiàn)代碼
- jquery 日期控件datepicker屬性詳細解析
- Jquery獲得控件值的三種方法總結(jié)
- jquery日歷控件實現(xiàn)方法分享
- JQuery EasyUI 日期控件如何控制日期選擇區(qū)間
- jquery+javascript編寫國籍控件
相關(guān)文章
jQuery ajax 當(dāng)async為false時解決同步操作失敗的問題
這篇文章主要介紹了 jQuery ajax 當(dāng)async為false時解決同步操作失敗的問題的相關(guān)資料,需要的朋友可以參考下2016-11-11jQuery頭像裁剪工具jcrop用法實例(附演示與demo源碼下載)
這篇文章主要介紹了jQuery頭像裁剪工具jcrop用法,結(jié)合實例形式分析了jQuery頭像裁剪工具jquery.jcrop.js具體使用技巧,并附帶了完整的demo源碼供讀者下載參考,需要的朋友可以參考下2016-01-01Jquery Ajax Error 調(diào)試錯誤的技巧
jquery在程序開發(fā)ajax應(yīng)用程序時提高了效率,減少了需要兼容性的問題,當(dāng)我們在ajax項目中,遇到ajax異步獲取數(shù)據(jù)出錯該怎么解決呢,我們可以通過捕捉error事件來獲取出錯的信息,本文給大家介紹jquery ajax error調(diào)試錯誤的技巧,感興趣的朋友一起學(xué)習(xí)吧2015-11-11jquery插件jquery.dragscale.js實現(xiàn)拖拽改變元素大小的方法(附demo源碼下載)
這篇文章主要介紹了jquery插件jquery.dragscale.js實現(xiàn)拖拽改變元素大小的方法,涉及jquery針對鼠標事件的響應(yīng)及頁面元素動態(tài)操作的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-02-02jQuery仿360導(dǎo)航頁圖標拖動排序效果代碼分享
這篇文章主要為大家詳細介紹了360導(dǎo)航頁圖標拖動排序效果代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-08-08