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

daylyknowledge1的更多相关文章

随机推荐

  1. Autofac容器使用属性进行WebApi自动注入

    背景 使用Autofac进行依赖注入时,经常遇到的场景是在容器中进行类似如下代码的注入操作: builder.RegisterType<BackInStockSubscriptionServic ...

  2. 【DataGuard】部署Data Guard相关参数详解 (转载)

    原文地址:[DataGuard]部署Data Guard相关参数详解 作者:secooler    有关物理Data Guard部署参考<[DataGuard]同一台主机实现物理Data Gua ...

  3. python3.6 实现AES加密的示例(pyCryptodome)

    当然我也是通过官方推荐,使用下面命令去下载安装的,pip就是好用...    pip install pycryptodome 撸码开始 废话不多说,直接上demo # from Crypto.Has ...

  4. C#遍历XmlDocument对象所有节点名称、类型、属性(Attribute)

    C#遍历XmlDocument对象所有节点名称.类型.属性(Attribute) 源码下载 代码 static void Main(string[] args) { System.Xml.XmlDoc ...

  5. CentOS 6.7 编译PHP7 make时出现错误:undefined reference to `libiconv_close’

    编辑Makefile文件,找到变量EXTRA_LIBS,并在末尾添上-liconv EXTRA_LIBS = -lcrypt -lz -lexslt -lcrypt -lrt -lmcrypt -ll ...

  6. 并发包学习(三)-AbstractQueuedSynchronizer总结

    J.U.C学习的第二篇AQS.AQS在Java并发包中的重要性,毋庸置疑,所以单独拿出来理一理.本文参考总结自<Java并发编程的艺术>第五章第二节队列同步器. 什么是AbstractQu ...

  7. centos7使用tinyproxy搭建简单http(s)服务器,无用户密码验证

    1  安装 yum install tinyproxy 2 查找配置文件地址 whereis tinyproxy.conf 3 编辑配置文件 vim tinyproxy.conf 把 allow 12 ...

  8. Python 测试题目-1

    l1 = [11,22,33]l2 = [22,33,44] # 1.获取内容相同的两个元素# 2.获取l1中有l2没有的元素# 3.获取l2中有l1中没有的元素# 4.获取l1 l2中内容都不通的元 ...

  9. MS SQL Server 无法添加、更新或删除从msx服务器上发起的作业(或其步骤或调度)

    因为 服务器 的名字 更改过 use   msdb     go         SP_CONFIGURE   'ALLOW UPDATES',1   RECONFIGURE   WITH   OVE ...

  10. Win7删除远程连接历史记录

    打开注册表,找到 HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default 删除右侧的 MRUn(n是索引号) 项 即可.