Web记录

JavaScript改变html元素属性

首先获取元素对象:

const image = document.getElementById("image")

改变css属性

大致格式为对象名.style.css属性= 属性值

image.style.display = "inline"

改变块本身属性

image.setAttribute("src", "url")

删除块

const img_div = document.getElementById('imgDiv')
img_div.parentNode.removeChild(img_div)

axios使用

axios导入

最简单的方法,在需要使用axios的html页面的最前面导入:

<script src="http://cdn.suoluomei.com/common/js2.0/axios/axios.min.js"></script>

向后端传值(POST)

<script>
axios({
       method:'post',
       url:'/choose_object',
    }).then((response) =>{
        console.log(response)
    }).catch((error) =>{
        console.log(error)
    })
</script>

从后端获取值(GET)

<script>
axios({
        method:'get',
        url:'/get_track_flag',
    }).then((response) =>{
        console.log(response)
    }).catch((error) =>{
        console.log(error)
    })
</script>

Flask使用

Flask返回图片流

后端

if request.method == 'GET':
        img_stream = open(os.path.join('D:/Code/GraduationProject/web/static/background.jpg'), "rb").read()
        response = make_response(img_stream)
        # 返回的内容类型必须修改
        response.headers['Content-Type'] = 'image/png'
        return response

前端

<script>
 axios({
            method:'get',
            url:'/test',
            responseType: 'blob',
        }).then(function (response) {
            console.log(response.data);
            const imgCodeUrl=window.URL.createObjectURL(response.data) // 后端返回前端渲染
            console.log(imgCodeUrl);
            const img_play = document.getElementById("img-play");
            img_play.setAttribute("src", imgCodeUrl)
        }).catch((error) =>{
            console.log(error)
        })
</script>

Flask框架下提交表单

前端:

action控制需要传递至后端的地址,method用来选择使用post还是get方法,下面代码中是利用下拉框选取单个值提交给后端,前端需要对每个传递的值都设置一个name,确保后端能够根据name获取指定的值

<form class="choose-tracker" action="/choose_tracker", method="post">
        <select name="tracker" class="select-style">
            <option value="1">1</option>
            <option value="2" selected="selected">2</option>
            <option value="3">3</option>
        </select>
        <input type="submit" value="S T A R T" class="submit-button">
</form>

后端

后端根据前端提交的的关键词来获取需要的值

@app.route("/choose_tracker", methods=['POST'])
def choose_tracker():
    if request.method == 'POST':
        parm = request.form.get('tracker')
        return
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

White Jiang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值