關(guān)于bootstrap日期轉(zhuǎn)化,bootstrap-editable的簡單使用,bootstrap-fileinput的使用詳解
數(shù)據(jù)庫中為datetime類型,.net讀取數(shù)據(jù)已Json格式發(fā)回給前臺頁面:例如:使用bootstrap表格插件Ⅹ
formatter: function (value, row, index) {
var date = new Date(parseInt(value.slice(6)));
return date.getFullYear() + '-' + parseInt(date.getMonth() + 1) + '-' + date.getDate() + " " + date.getHours() + ":" + date.getMinutes()+":"+date.getSeconds();
}
使用bootstrap-editable時需要引用
<script src="~/Scripts/bootstrap3-editable/js/bootstrap-editable.min.js"></script> <script src="~/Scripts/bootstraptable/dist/extensions/editable/bootstrap-table-editable.min.js"></script>
初始化時:
{
field: 'SkuPurchasePrice',
title: '采購價',
align: 'center',
editable: {
type: 'text',
title: '采購價',
validate: function (v) {
if (v < 0) return '采購價不能小于0';
}
}
}, {
field: 'QtyAvailable',
title: '庫存可用量',
align: 'center',
editable: {
type: 'text',
title: '庫存可用量',
validate: function (v) {
if (v < 0) return '庫存可用量不能小于0';
},
},
}
事件:
onEditableSave: function (field, row, oldValue, $el) {
$.ajax({
type: 'post',
url: "@Url.Action("EditNumber")",
dataType: 'JSON',
data: { "row": JSON.stringify(row) },
success: function (data) {
if (data.ResultType == 0) {
toastr.success(data.Message);
}
else {
toastr.warning(data.Message);
}
},
error: function () {
toastr.error("出錯了,請聯(lián)系管理員");
}
});
}
bootstrap-fileinput使用:
引用
<script src="~/Scripts/AdminLTE2.3.0/bootstrap/js/fileinput.min.js"></script>
初始化:
<label class="control-label col-sm-1">商品上傳</label>
<div class="col-sm-2"><input type="file" id="ProductsUpload" name="ProductsUpload" /></div>
<div class="col-sm-1"><a href="~/ProductsExcel/DownloadTemplate?type=5" rel="external nofollow" target="_blank">下載模板</a></div>
function initFileInput(ctrlName) {
var control = $('#' + ctrlName);
control.fileinput({
language: 'zh', //語言
uploadUrl: "@Url.Action("ExcelLeadingIn")", //action
autoReplace: true,
maxFileCount: 1, //最大上傳數(shù)量
allowedFileExtensions: ["xlsx", "xls"],
browseClass: "btn btn-primary", //按鈕樣式
dropZoneEnabled: false,
enctype: 'multipart/form-data',
showRemove: true, //是否顯示刪除按鈕
showBrowse: true, //顯示瀏覽圖片按鈕
msgFilesTooMany: "選擇上傳的文件數(shù)量({n}) 超過允許的最大數(shù)值{m}!",
msgInvalidFileExtension:"只支持.xlsx和.xls文件的格式上傳",
fileActionSettings: {
showUpload: false, //預(yù)覽圖片上傳按鈕
showRemove: false, //預(yù)覽圖片remove按鈕
showZoom: false //關(guān)閉預(yù)覽圖片按鈕
}
}).on('fileuploaded', function (event, data, previewId, index) {//上傳圖觸發(fā)事件
if (data.response.state == 1) {
$('#excelLendingDiv h5').html($('#excelLendingDiv h5').html() + data.response.result+"<br/>");
}
else {
toastr.error(data.response.result);
}
}).on('filecleared', function (event) {//remove觸發(fā)事件
control.show();
});
}
后臺上傳:
[HttpPost]
public ActionResult ExcelLeadingIn()
{
var files = Request.Files;
string name=files.Keys[0].ToString();
if (files != null && files.Count > 0)
{
var file = files[0];
string path = Server.MapPath("~/Content/excel/") + file.FileName;//文件保存在當(dāng)前域名下的Content/excel/中
file.SaveAs(path);
string mess = OfferServer.ProductsDetail.InsertExcel(path,file.InputStream,name);
return Json(new { state = 1, result = mess });
}
return Json(new { state = 0, result = "上傳發(fā)生錯誤,請檢查后重試" });
}
以上所述是小編給大家介紹的關(guān)于bootstrap日期轉(zhuǎn)化,bootstrap-editable的簡單使用,bootstrap-fileinput的使用詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
JavaScript代碼性能優(yōu)化總結(jié)(推薦)
下面小編就為大家?guī)硪黄狫avaScript代碼性能優(yōu)化總結(jié)(推薦)。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨小編過來看看吧,祝大家游戲愉快哦2016-05-05
JavaScript之class繼承_動力節(jié)點Java學(xué)院整理
這篇文章主要介紹了JavaScript之class繼承,新的關(guān)鍵字class從ES6開始正式被引入到JavaScript中。class的目的就是讓定義類更簡單,有興趣的可以了解一下2017-07-07
微信小程序網(wǎng)絡(luò)層封裝的實現(xiàn)(promise, 登錄鎖)
這篇文章主要介紹了微信小程序網(wǎng)絡(luò)層封裝(promise, 登錄鎖),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05

