Python 学习第十八天 js 正则及其它前端知识
一,js 正則表達(dá)式
test 判斷制度串是否符合規(guī)定的正則
(1)定義正則表達(dá)式匹配規(guī)則
??????? js 中定義正則表達(dá)式為rep=/\d+/,兩個(gè)//之間為正則模式
(2)rep.test("assdsda89sdasdas") ,返回true,一般test 方法為只要字符串中的包含正則模式即返回true
(3)rep=/^\d+$/完全匹配正則模式
?? exec 獲取匹配的數(shù)據(jù)
1, (1)rep=/\d+/;
(2)str="wangshen_67_houyanfa_20"
(3)rep.exec(str) 返回["67"]
2,?? js exec 分組匹配
text="JavaScript is more fun than Java or JavaBeans!" var pattern = /\bJava(\w*)\b/; pattern.exec(text) #返回 ["JavaScript", "Script"]???? 3,js exec 全局匹配
text="JavaScript is more fun than Java or JavaBeans!" var pattern = /\bJava\w*\b/g; pattern.exec(text) # ["JavaScript"] pattern.exec(text) # ["Java"] pattern.exec(text) # ["JavaBeans"] pattern.exec(text) # null pattern.exec(text) #加g表示全局匹配,匹配一個(gè)輸出一個(gè),當(dāng)全部匹配完成時(shí)輸出null 再匹配從頭開(kāi)始?? 4,js exec 全局加分組匹配
JavaScript is more fun than Java or JavaBeans! var pattern = /\bJava(\w*)\b/g; # ["JavaScript",'Script'] # ["Java", ""] # ["JavaBeans", "Beans"] # null #分組匹配會(huì)對(duì)匹配到的結(jié)果再進(jìn)行一次匹配?5,其它匹配模式
(1)/.../i 不區(qū)分大小寫(xiě)
(2)/.../m 表示多行匹配,js 中默認(rèn)支持多行匹配,也就是單獨(dú)加g也可以完成多行匹配,但是在匹配模式中^$,匹配多行時(shí)需要m參數(shù)
?????? 例如
text="JavaScript is more fun than \n Java or JavaBeans!" var pattern = /\bJava(\w*)\b/g; pattern.exec(text) #返回["JavaScript",'Script'] 也可以匹配成功,表示默認(rèn)支持多行 text="JavaScript is more fun than \n Java or JavaBeans!" var pattern = /^Java(\w*)/g; #匹配以Java開(kāi)頭的字符串,且后面為任意字符 pattern.exec(text) #返回["JavaScript",'Script'] pattern.exec(text) #返回null var pattern = /^Java(\w*)/gm; pattern.exec(text) #返回["JavaScript",'Script'] pattern.exec(text) #返回["Java",""]?6,a標(biāo)簽綁定事件
<a οnclick='return Func();'>asdf</a> function Func(){return false: #利用DOM綁定方式增加a標(biāo)簽事件 }<a>asdf</a> $('a').click(function(){return false;}) #利用jquery方式綁定事件?7,form 表單提交事件
<form> <input type='text' /><input type='password' /><input type='submit' /> </form>$(':submit').click(function(){ $(':text,:password').each(function(){...return false;})return false; })?8,標(biāo)簽定義事件執(zhí)行順序
像a input submit 標(biāo)簽一般默認(rèn)都為自定義事件先執(zhí)行,checkbox 默認(rèn)事件先執(zhí)行
?9,css設(shè)置重要性
<style>.no-radus{border-radius:0 !important; } </style>?二,django
?1,django 設(shè)置靜態(tài)文件路徑
在setting.py中最下面添加添加以下代碼
STATIC_URL = '/static/'STATICFILES_DIRS = {os.path.join(BASE_DIR,'static'),}
?2,創(chuàng)建完django project 后的操作
(1),配置模板的路徑
TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [os.path.join(BASE_DIR, 'templates')],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},](2),配置靜態(tài)文件的路徑
#在 setting.py 中添加 STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), ) #在html中添加 <link rel="stylesheet" href="/static/commons.css" />?3,view.py獲取用戶提交的數(shù)據(jù)
if request.method == "post":user = request.POST.get(‘user',None)pwd = request.POST.get('pwd',None) #獲取用戶提交的數(shù)據(jù)中 即使不存在相應(yīng)的值也不會(huì)報(bào)錯(cuò)user = request.POST['user']pwd = request.POST['pwd'] #獲取用戶提交的數(shù)據(jù)。如果不存在就會(huì)報(bào)錯(cuò)?4,view.py中函數(shù)處理重定向到其它網(wǎng)址
from django.shortcuts import redirect #導(dǎo)入模塊return redirect('http://www.baidu.com') #在view函數(shù)中添加,重定向到其它網(wǎng)站from django.shortcuts import render
return render(request,'login.html') #找到本地的模板,打開(kāi)html文件
?5,render 返回錯(cuò)誤信息
return render(request,'login.html',{'error_msg':error_msg})
?6,django 處理html模板for 循環(huán)與取某一個(gè)值
{% for row in user_list %}<tr> <td>{{ row.username }}</td><td>{{ row.gender }}</td><td>{{ row.email}}</td></tr> { %endfor %} #部分html代碼def home(request):return render(request,'home.html',{'user_list': USER_LIST}} #部分views.py代碼?7,css input 框中提示字設(shè)置
<input type="text" name="username" placeholder="用戶名" />
?8,django 已get方式獲取值,需要在url中增加值
???? 例如:
?
轉(zhuǎn)載于:https://www.cnblogs.com/system-public/p/6132392.html
總結(jié)
以上是生活随笔為你收集整理的Python 学习第十八天 js 正则及其它前端知识的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 支付和清算就是信息流和资金流
- 下一篇: Mysql数据库的使用总结之ERROR
