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的更多相关文章
随机推荐
- hihocoder-1080题解
一.题目链接 http://hihocoder.com/problemset/problem/1080 二.题意 一维区间,需要做区间增加和区间置值,以及对整个区间求和. 三.思路 显然线段树是个利器 ...
- Check failed: mdb_status == 0 (2 vs. 0) No such file or directory
运行 ./examples/mnist/train_lenet.sh 时,碰到了这个问题. 一定是路径问题!!!仔细查看prototxt文件里面的各种路径!!! 解决方案: 把.prototxt里 ...
- AngularJS学习笔记(2)——与用户交互的动态清单列表
与用户交互的动态清单列表 以我之前写的一个清单列表页面作为例子(MVC模式的清单列表效果),优化前代码如下: <!DOCTYPE html> <html ng-app="t ...
- 一行代码让App运行时iPhone不会进入锁屏待机状态
转自:http://www.cocoachina.com/iphonedev/sdk/2010/1028/2260.html 如果你不希望应用运行时 iPhone 进入锁屏待机状态,加入下面这行代码即 ...
- Struts 2 常用技术
目录 Struts 2 常用技术 1. 常用类和接口 1.1 getter 和 setter 方法 1.2 Action 接口 1.3 ActionSupport 类 1.4 通过 Act ...
- mongoTemplate.aggregate()聚合查询
一.概述 1. 聚合的表达式 MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*). 下表展示了一些聚 ...
- idea git 操作
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...
- LevelDB Version
[LevelDB Version] Version 保存了当前磁盘以及内存中所有的文件信息,一般只有一个Version叫做"current" version(当前版本).Level ...
- 牛X的FieldBlur
[牛X的FieldBlur] Use Field Blur to build a gradient of blurs, by defining multiple blur points with di ...
- protobuf's extension
[protobuf's extension] extension允许第三方扩展协议,开发方需要像下面这样定义: 扩展方需要像下面这样扩展: 使用的时候必须用SetExtension方法: 参考:htt ...