daylyknowledge1
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的更多相关文章
随机推荐
- 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #13 使用Block I/O控制器设置I/O优先级
HACK #13 使用Block I/O控制器设置I/O优先级 本节介绍使用Block I/O控制器的功能设置I/O优先级的方法.Block I/O控制器可以将任意进程分组,并对该分组设置I/O的优先 ...
- windows下手动安装pyinstaller(python2.7)
1.首先,安装python2.7.13,官网下载msi版(windows直接安装): https://www.python.org/downloads/ 2.然后,到python包官网依次下载,fut ...
- Struts 2 常用技术
目录 Struts 2 常用技术 1. 常用类和接口 1.1 getter 和 setter 方法 1.2 Action 接口 1.3 ActionSupport 类 1.4 通过 Act ...
- centos禁止 You have new mail in /var/spool/mail/root提示
在/etc/profile 增加unset MAILCHECK
- realproxy
https://msdn.microsoft.com/zh-cn/library/dn574804.aspx
- 更改Mysql数据库数据存储位置的具体步骤
首先把mysql的服务先停掉,更改MySQL配置文件My.ini中的数据库存储主路径,将老的数据库存储主路径中的数据库文件和文件夹复制到新的存储主路径,接下来重启搞定. 一.首先把mysql的服务先停 ...
- TouchEvent里的targetTouches、touches、changedTouches的区别的具体体现是?
touches:当前屏幕上所有触摸点的集合列表 targetTouches: 绑定事件的那个结点上的触摸点的集合列表 changedTouches: 触发事件时改变的触摸点的集合 举例来说,比如div ...
- interrupt和isInterrupted的基本使用方法
java线程是协作式,而非抢占式 调用一个线程的interrupt() 方法中断一个线程,并不是强行关闭这个线程,只是跟这个线程打个招呼,将线程的中断标志位置为true,线程是否中断,由线程本身决定. ...
- 命令--cut
--按文件大小排序 显示前100行 显示后五列 ll -Sh|head -n 100|cut -d ' ' -f 5- 一.基本语法cut是一个选取命令,以行为单位,用指定分隔符将行切分为若干字段,选 ...
- Golang 字符编码
需要添加的库 go get code.google.com/p/go.text/encoding go get code.google.com/p/go.text/transform 两个转码函数 i ...