日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

Python 学习第十八天 js 正则及其它前端知识

發(fā)布時間:2024/4/17 HTML 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python 学习第十八天 js 正则及其它前端知识 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一,js 正則表達(dá)式

  test 判斷制度串是否符合規(guī)定的正則

  (1)定義正則表達(dá)式匹配規(guī)則

  ??????? js 中定義正則表達(dá)式為rep=/\d+/,兩個//之間為正則模式

  (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表示全局匹配,匹配一個輸出一個,當(dāng)全部匹配完成時輸出null 再匹配從頭開始

?? 4,js exec 全局加分組匹配

JavaScript is more fun than Java or JavaBeans! var pattern = /\bJava(\w*)\b/g; # ["JavaScript",'Script'] # ["Java", ""] # ["JavaBeans", "Beans"] # null #分組匹配會對匹配到的結(jié)果再進(jìn)行一次匹配

?5,其它匹配模式

  (1)/.../i 不區(qū)分大小寫

  (2)/.../m 表示多行匹配,js 中默認(rèn)支持多行匹配,也就是單獨加g也可以完成多行匹配,但是在匹配模式中^$,匹配多行時需要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開頭的字符串,且后面為任意字符 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)的值也不會報錯user = request.POST['user']pwd = request.POST['pwd'] #獲取用戶提交的數(shù)據(jù)。如果不存在就會報錯

?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') #找到本地的模板,打開html文件

?5,render 返回錯誤信息

  return render(request,'login.html',{'error_msg':error_msg})

?6,django 處理html模板for 循環(huán)與取某一個值

{% 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中增加值
???? 例如:

http://127.0.0.1:8009/home?nid=123&name=jack #get方式請求#views函數(shù)中 print(request.GET) #返回 <QueryDict:{'name':[alex],'nid':['123']}> print(request.GET.get('nid')) #返回 123

?

轉(zhuǎn)載于:https://www.cnblogs.com/system-public/p/6132392.html

總結(jié)

以上是生活随笔為你收集整理的Python 学习第十八天 js 正则及其它前端知识的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。