摘要
up在写js的时候,有时候感觉知识点有些分散,但这些知识点确实需要掌握的,这篇文章的目的就是将生活中遇到的js零碎知识点整理出来,一是用于以后方便查看,二是梳理一哈知识点
1. 网页中url的获取
-
常见的2种url:
第2种是网址后面携带附加内容,使用 ? 开头, 中间用 & 分割
wd= 这种是名,跟在后面的是它的内容
访问这种,路由的提交是提交这个网址,但是路由的接收是第一种的url
(2)https://www.baidu.com/s?wd=%E4%B8%96%E7%95%8C&rsv_spt=1
例:提交
$(document).ready(function () {
var path = location.search;
$.get('/house/allsearch/' + path, function(data){
}
});
})
获取:
@house.route('/allsearch/', methods=['GET'])
def house_search():
search_dict = request.args
area_id = search_dict.get('aid')
start_date = search_dict.get('sd')
end_date = search_dict.get('ed')
-
在js中获得当前网页?后面的内容
path = location.search
2.js中网页的跳转
location.href = 'https://www.baidu.com'
2.js中网页的替换
var path = location.search.replace('当前内容', '替换后的内容');
location.href = path
3.值得获取与赋值
- 获取
$('#real-name').val()
- 赋值
$('#real-name').val(data.id_name)
4.重写一个html
$('.orders-list').html(lorders_html);
5.获取父类元素的一个属性
image.png
var order_id = $(this).parents('li').attr('order-id');
6.给指定标签赋属性和值
$(".modal-comment").attr("order-id", orderId);
7.显示与隐藏
$("#mobile-err").show();
$("#mobile-err").hide();
8.追加网页
$('#houses-list').append(house_list_html)
9.模块动态隐藏
modal('hide')
$('#accept-modal').modal('hide');
10.切割路径
var path = location.search;
id = path.split('=')[1];