weui提示框
$.toast("验证是否停机!",'text')
$.toast('请填写正确账号!', 'cancel');
$.toast('手机绑定成功!', 'can');
$.showLoading("数据加载中");
$.hideLoading();
uexWindow.toast("0", "5", "错误", "2000") (这是Appcan的)
时间延迟
setTimeout(function() { },1000)
周期(以毫秒计)来调用函数:
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。
开始:var int=self.setInterval("clock()",50)
取消:<button onclick="int=
window.clearInterval(int)">
获取下拉框的选项值
现在有一id=test的下拉框,怎么拿到选中的那个值呢?
分别使用javascript原生的方法和jquery方法
<select id="test" name="">
<option value="1">text1</option>
<option value="2">text2</option>
</select>
1:var options=$("#test option:selected"); //获取选中的项
2:alert(options.val()); //拿到选中项的值
3:alert(options.text()); //拿到选中项的文本
阻止冒泡
event.stopPropagation();
Event 对象代表事件的状态,比如事件在其中发生的元素、键盘按键的状态、鼠标的位置、鼠标按钮的状态。
截取字符串
substring() 方法用于提取字符串中介于两个指定下标之间的字符。
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
var a = lifePlanNoteImgPath.substring(lifePlanNoteImgPath.indexOf("upload"));
alert(a)
请求地址替换
var url= "http://localhost:8081/myAuthorize?name=NAME&pw=PASSWORD";
url = url.replace("NAME","201712170105");//来自缓存中的用户名
url = url.replace("PASSWORD","170105");//来自缓存中的密码
console.dir(url);
each循环
$(".ys").each(function(){
console.log($(this).val())
});
数组赋值
var strs_rms= new Array(); //定义一数组
for (var i=0; i < data.length; i++) {
strs_rms.push(data[i].food_num)
};
字符串分隔
var strs= new Array(); //定义一数组
strs=data[0].fr_sc.split(",");
console.log(strs);
for (var i=0; i < strs.length; i++) {
console.log(strs[i]);
};
//给删除按钮绑定点击事件(传值)
$('.del').on('click',function () {
// 事件处理事件
var idObj = $(':checkbox:checked');
var id = '';
for (var i = 0; i < idObj.length; i++) {
id += idObj[i].value + ',';
}
//去掉最后一个,
id = id.substring(0,id.length -1);
console.log(id);
})
placeholder的样式设置
获取weui复选框的值
var inputa = $("input[name='checkbox1']:checked");
for (var i = 0; i < inputa.length; i++) {
console.log(inputa[i].id);
console.log($('#'+inputa[i].id+'').parents('td').next().text());
console.log($('#'+inputa[i].id+'').parents('td').next().next().text());
}
点击事件嵌套多次触发问题
jQuery中的click事件会累计绑定,所以我们可以在下次点击前先解绑
$(".xx").unbind("click").on("click",function(){
});
CSS文字溢出
text-overflow:ellipsis
属性来实现单行文本的溢出显示省略号(…)。当然部分浏览器还需要加宽度width
属性
单行:
overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
多行:
overflow : hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;
城别.笔