
需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:indexhtml,并引入jquery。
2、在indexhtml中的<script>标签,输入jquery代码:$('img')attr('src', 'small3png');。
3、浏览器运行indexhtml页面,此时成功用jquery把地址放入了img标签的src中。
js中获取image的src值的语句:
var path = $('#suolue')attr('src');
var path = documentgetElementById("suolue")src;
var path = $("#suolue")[0]src;
以上三种方法都可以,具体输出内容可以alert()出来调试一下就知道啦~
文件名后面多了一个斜杠,这应该是后台发送代码时多添加的,应该在后台代码中找原因,这个错误不除,前端js是不可能正常获取src属性的。
如果是静态html页面,那就手工把那个多余的斜杠删掉吧。
Copyright © 1999-2020, CSDNNET, All Rights Reserved
python
打开APP
pergoods
关注
Python多线程爬取网站image的src属性实例 原创
2017-05-16 11:18:51
pergoods
码龄6年
关注
# coding=utf-8
'''
Created on 2017年5月16日
@author: chenkai
Python多线程爬取某单无聊图地址(requests+BeautifulSoup+threading+Queue模块)
'''
import requests
from bs4 import BeautifulSoup
import threading
import Queue
import time
class Spider_Test(threadingThread):
def __init__(self,queue):
threadingThread__init__(self)
self__queue = queue
def run(self):
while not self__queueempty():
page_url=self__queueget() [color=red]#从队列中取出url[/color]
print page_url
selfspider(page_url)
def spider(self,url):
r=requestsget(url) [color=red]#请求url[/color]
soup=BeautifulSoup(rcontent,'lxml') [color=red]#rcontent就是响应内容,转换为lxml的bs对象[/color]
imgs = soupfind_all(name='img',attrs={}) #查找所有的img标签,并获取标签属性值(为列表类型)
for img in imgs:
if 'onload' in str(img): [color=red]#img属性集合中包含onload属性的为动态图gif,[/color]
print '>
以上就是关于如何把jquery的值放入img标签的src里面全部的内容,包括:如何把jquery的值放入img标签的src里面、在js 或者jquery 里怎么判断一个img标签有没有data-src属性、js获取img的src属性出错,求大佬指导等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)