daylyknowledge1

来源:https://www.cnblogs.com/beingdone/archive/2018/07/28/9381249.html
-Advertisement-
Play Games

1.資料庫截取字元串:toFixed():四捨五入substring(cp_introduce,0,11) cp_introduce前臺截取: field: 'an_content', title: '問題內容', formatter: function (value) { if (value.le ...


1.資料庫截取字元串:
toFixed():四捨五入
substring(cp_introduce,0,11) cp_introduce
前臺截取:
field: 'an_content',
title: '問題內容',
formatter: function (value) {
if (value.length > 25) {
return value.substring(0, 25) + "…";
} else {
return value;
}
}
convert(nvarchar(10),field,120)

2.覆選框
設置

<input type="checkbox" value="1" name="sProblem">check1
<input type="checkbox" value="2" name="sProblem">check2
<input type="checkbox" value="3" name="sProblem">check3
<input type="checkbox" value="4" name="sProblem">check4

取值
獲取選中的checkbox的val,併合成為一個字元串以逗號隔開。
function getTheCheckBoxValue(){
var test = $("input[name='sProblem']:checked");
var checkBoxValue = "";
test.each(function(){
checkBoxValue1 += $(this).val()+",";
})
checkBoxValue = checkBoxValue.substring(0,checkBoxValue.length-1);

3.設置文本框只讀的2種方式(不要用到style)
disabled:disabled
readonly:readonly

4.
selectListItem綁定數據
固定的數據

List<SelectListItem> wlist = new List<SelectListItem>();
wlist.Add(new SelectListItem { Text = "經驗不限", Value = "0" });
wlist.Add(new SelectListItem { Text = "無經驗", Value = "1" });
wlist.Add(new SelectListItem { Text = "1年以下", Value = "2" });
wlist.Add(new SelectListItem { Text = "1-3年", Value = "3" });
wlist.Add(new SelectListItem { Text = "3- 5年", Value = "4" });
wlist.Add(new SelectListItem { Text = "5- 10年", Value = "5" });
wlist.Add(new SelectListItem { Text = "10年以上", Value = "6" });
ViewBag.wlist = wlist;
獲取資料庫的數據:
ViewBag.wlist = 數據源;

前臺獲取
<select id="jp_Education" name="jp_Education">
<option value="-1">請選擇學歷</option>
@foreach (var item in ViewBag.elist)
{
<option value="@item.Value">@item.Text</option>
}
</select>

5.省市聯動
引用的js文件:
<script src="~/Content/assets/data.js"></script>
<script src="~/Content/assets/jquery-1.12.4.js"></script>
<script src="~/Content/assets/province.js"></script>

html代碼:

<div class="form-group layui-form-item">
<div class="layui-form-item">
<label class="layui-form-label">工作地區</label>
<div class="layui-input-inline">
<select name="provid" id="provid" lay-filter="provid">
<option value="">請選擇省</option>
</select>
</div>
<div class="layui-input-inline">
<select name="cityid" id="cityid" lay-filter="cityid">
<option value="">請選擇市</option>
</select>
</div>
<div class="layui-input-inline">
<select name="areaid" id="areaid" lay-filter="areaid">
<option value="">請選擇縣/區</option>
</select>
</div>
</div>
</div>

js代碼:
獲取地區
var jp_address1 = $("#provid option:selected").text();
var jp_address2 = $("#cityid option:selected").text();
var jp_address3 = $("#areaid option:selected").text();
var jp_address = jp_address1 + " " + jp_address2 + " " + jp_address3;

6.嵌套的三元運算符
示例:
審核狀態:
<span>
@(ViewBag.company.cp_type == 0 ? "待審核" :
ViewBag.company.cp_type == 1 ? "通過" :
ViewBag.company.cp_type == 2 ? "未通過" : "")
</span>

7.百度富文本編輯器
引用的js文件:
<script src="~/Content/ueditor/ueditor.config.js"></script>
<script src="~/Content/ueditor/ueditor.all.min.js"></script>

html代碼:
<div class="form-group layui-form-item">
<label class="layui-form-label">任職要求</label>
<div class="layui-input-block">
<script id="content" type="text/plain" style="width:100%;">
</script>
<textarea id="jp_description" name="jp_description" style="display:none;" ></textarea>
</div>
</div>
js代碼:
初始化富文本編輯器:

$(function () {
//百度富文本初始化
UE.getEditor('content',{
initialFrameHeight: 200
})
});
獲取富文本輸入的內容:
var jp_description = UE.getEditor('content').getContentTxt();

8.layui頁面渲染:
layui.use('form', function (){
var form = layui.form;
//但是,如果你的HTML是動態生成的,自動渲染就會失效
//因此你需要在相應的地方,執行下述方法來手動渲染,跟這類似的還有 element.init();
form.render();
});

9.圖片上傳(上傳不同的圖片使用不同的id)

引用的js文件:
<script src="~/Content/js/ajaxfileupload.js" type="text/javascript"></script>

html代碼:
<div id="attachs2" class="form-group layui-form-item">
<input type="hidden" class="form-control" id="attach2" name="attach2" v-model="JSON.stringify(items2)" value="">
<label class="layui-form-label">公司logo</label>
<div class="layui-input-block">
<div class="input-group">
<div class="input-group-btn">
<a onclick="$('#file2').click()" class="btn btn-link"><i class="glyphicon glyphicon-plus"></i>上傳公司logo</a>
<input id="file2" name="file2" type="file" multiple="multiple" onchange="addAttach2('圖片上傳到的文件夾')" class="hide" />
</div>
</div>
<div class="input-group">
<span v-for="(item,index) in items2">
<a v-bind:href="[item.path]" target="_blank"><img v-bind:src="[item.path]" style="width:50px;" target="_blank" />{{item.name}}</a>
<a class="btn btn-link" v-on:click="remove(index)">刪除</a>
</span>
</div>
</div>
</div>

js代碼:

//上傳公司logo圖片
var attachs2 = new Vue({
el: '#attachs2',
data: { items2: [] },
created: function (){
if ($('#attach2').val() != '') { this.items2 = JSON.parse($('#attach2').val()); }
},
methods:{
remove: function (index){
var path = this.items2[index]['path'];
$.ajax({
url: '/Upload/Delete',
data: { 'path': path },
success: function (data){; }
})
this.items2.splice(index, 1);
}
}
});

attachs2.$watch("items2", function (){
showattachs.items2 = attachs2.items2;
})

var showattachs = new Vue({
el: "#showattachs",
data: { items2: [] },
created: function (){
this.items = attachs2.items;
}
})

function addAttach2(path){
$.ajaxFileUpload({
url: '/Upload/FileList/',
data: { 'path': path },
secureuri: false,
fileElementId: 'file2',
dataType: 'HTML',
success: function (data) {
attachs2.items2 = attachs2.items2.concat(JSON.parse(data));
}
})
}
上傳圖片的專用控制器:
using System;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Mvc;

namespace ApiProject.Controllers
{
public class UploadController : Controller
{
public ActionResult Index()
{
return View();
}
public Dictionary<string,object> UploadFile(string path)
{
Dictionary<string, object> data = new Dictionary<string, object>();

string userPath = "/Files/Job/";
if (!Directory.Exists(Server.MapPath(userPath))) { Directory.CreateDirectory(Server.MapPath(userPath)); }
string dir = userPath + "/" + path;
if (!Directory.Exists(Server.MapPath(dir))) { Directory.CreateDirectory(Server.MapPath(dir)); }

HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
if (hfc.Count > 0)
{
string fileName = Path.GetFileNameWithoutExtension(hfc[0].FileName);
string ext = Path.GetExtension(hfc[0].FileName);
string filePath = dir + "/" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ext;
hfc[0].SaveAs(Server.MapPath(filePath));

data["name"] = fileName;
data["path"] = filePath;
return data;
}
else
{
return null;
}
}
public ActionResult FileList(string path)
{
string userPath = "/Files/Job/";//圖片保存的路徑
if (!Directory.Exists(Server.MapPath(userPath))) { Directory.CreateDirectory(Server.MapPath(userPath)); }
string dir = userPath + "/" + path;
if (!Directory.Exists(Server.MapPath(dir))) { Directory.CreateDirectory(Server.MapPath(dir)); }
HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
StringBuilder sb = new StringBuilder();
sb.Append("[");
for (int i = 0; i < files.Count; i++)
{
string fileName = Path.GetFileNameWithoutExtension(files[i].FileName);
string ext = Path.GetExtension(files[i].FileName);
string filePath = dir + "/" + DateTime.Now.ToString("yyyyMMddHHmmssfff")+i+ ext;
files[i].SaveAs(Server.MapPath(filePath));
sb.Append("{\"name\":\"" + fileName + "\",\"path\":\"" + filePath + "\" }");
if (i < files.Count-1) { sb.Append(","); }
}
sb.Append("]");
return Content(sb.ToString());
}
public ActionResult File(string path)
{
Dictionary<string,object> data = UploadFile(path);
if (data != null)
{
return Content("{\"name\":\"" + data["name"].ToString() + "\",\"path\":\"" + data["path"].ToString() + "\"}");
}
else
{
return Content("");
}
}
public void Delete(string path)
{
System.IO.File.Delete(Server.MapPath(path));
}
}
}

10.
點擊button自動提交表單原因及解決方案

原因
出現上述的問題主要是button標簽的type屬性惹的禍,button的type屬性值有三個分別為button、submit、reset。當我們在利用button標簽寫一個按鈕且沒有指定其type屬性時,IE7以下版本(具體是IE7以下還是IE5以下給忘了)會預設指定為button,其他會被預設指定為submit。當按鈕的type屬性被指定為submit的時候,點擊它會提交表單。

解決
當需在form標簽中放置一個button的時候,如果這個按鈕不是做提交表單的,切記一定要設置其type為button。

11.z-index


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 本文為原創,轉載請註明出處:https://www.cnblogs.com/Tom-shushu/p/9383066.html 本篇內容主要介紹:通過Servlet,JSP,Bootstrap框架以及MySQL等知識實現一個簡單地對資料庫信息進行:增,刪,改,查,分頁的操作; <一>設計資料庫 這裡 ...
  • try:將有可能導致出現異常的語句放到try塊中,如果使用了try語句後,後面的程式必須至少要跟一個except或者finally,否則程式會報錯 except:捕獲try塊中可能出現的異常 finally:不管程式是否有無異常,都會最終執行該語句 for example as below: 結果如 ...
  • C++自定義String字元串類 實現了各種基本操作,包括重載+號實現String的拼接 findSubStr函數,也就是尋找目標串在String中的位置,用到了KMP字元串搜索演算法。 include include using namespace std; class String; class ...
  • Java編程中獲取鍵盤輸入實現方法及註意事項 1. 鍵盤輸入一個數組 package com.wen201807.sort; import java.util.Scanner; public class Main { public static void main(String[] args) { ...
  • 1>:首先在CMD命令行中輸入:fsutil resource setautoreset true c:\ 2>:然後在運行services.msc 3>:找到Windows Process Activation Service服務 啟動該服務,啟動類型:自動 4>:繼續找到World Wide W ...
  • 最近面試時很多面試官都問到了EF框架 好記性不如爛筆頭 趕緊記下來 code-first是EF框架中的一種,是使用實體類來進行資料庫表的映射,所以實體類中的欄位要規範(我認為) 比如: 如果有外鍵的話 一定要搞清楚一對多、多對一和多對多的關係 比如一個用戶對應一個用戶詳細信息可以寫成這樣: 用戶詳細 ...
  • 首先先介紹一下這個項目,該項目實現了文本寫入及讀取,日誌寫入指定文件夾或預設文件夾,日誌數量控制,單個日誌大小控制,通過約定的參數讓用戶可以用更少的代碼解決問題。 1.讀取文本文件方法 使用:JIYUWU.TXT.TXTHelper.ReadToString(“文件物理路徑”) 1 public s ...
  • 一個典型的ASP.NET Core應用程式會包含Program與Startup兩個文件。Program類中有應用程式的入口方法Main,其中的處理邏輯通常是創建一個WebHostBuilder,再生成WebHost,最後啟動之。 而在創建WebHostBuilder時又會常常會指定一個Startup ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...