我有的html结构是这样的:
<ul id="something">
<li>
<a href="">
<img src="http://domain.com/directory/file1-128x79.jpg">
</a>
</li>
<li>
<a href="">
<img src="http://domain.com/directory/file2-128x79.jpg">
</a>
</li>
<li>
<a href="">
<img src="http://domain.com/directory/file3-128x79.jpg">
</a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我正在尝试将文件名从文件#-128x79.jpg更改为文件#-896x277.jpg.
我不知道如何获取动态生成的文件名并搜索和替换src更改.
我找到了用'none'替换整个src的方法,以确保我到目前为止做到了,但我不知道如何做其余的事情.
$('#something').removeAttr('id').prop('class', 'some-class').find('img').prop('src', 'none');
Run Code Online (Sandbox Code Playgroud) 我知道你可以检查一个元素是否存在$('div').length,但是当一个元素被销毁时.remove(),.length仍然会报告div存在.我怎样才能发现它是否真的存在?
if ($('div').length) {
alert('yes')
} else {
alert('no')
}
Run Code Online (Sandbox Code Playgroud) 我正在使用jQuery并且我正在尝试编写模式替换,但它不起作用.我有这个:
var $featured_rewrite = $('#featured').not('.slideshow');
$featured_rewrite.children().attr('href', $featured_rewrite.find('img').attr('src').replace('/-[0-9]+x[0-9]+\./i', '.'));
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这样的事情有效:
.replace('-500x277.', '.')
Run Code Online (Sandbox Code Playgroud)
但不是这个,我甚至用工具检查过并确保它有效且有效:
.replace('/-[0-9]+x[0-9]+\./i', '.')
Run Code Online (Sandbox Code Playgroud) 我只是想知道将表单放在带有html5的页面上的正确方法.我似乎找不到有关表格的任何信息.
我的页面是一个联系页面,其中包含带有标题和所有(Wordpress页面)的文章元素中的内容.我正在向页面添加联系表单,它有一个标题.他们应该在一个<section>还是一个<div>?
<div>
<h3>title</h3>
<form></form>
</div>
Run Code Online (Sandbox Code Playgroud)
要么
<section>
<header>
<h3>title</h3
</header>
<form></form>
</section>
Run Code Online (Sandbox Code Playgroud) 例:
<ul>
<li>
<a></a>
</li>
<li>
<a></a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我可以$('ul').children('li').get(0);用来获取列表项.我如何.children('a')用来遍历树?
我尝试了类似$('ul').children('li').get(0).children('a');但不起作用的东西.
备查:
li不是遍历到a,这就是我试图使用的原因.children().这就是为什么.eq()是首选答案.现在我可以这样做:
_load = function(index) {
image_get = thumbs.children('li').eq(index);
[...]
$(function() {
var img = $(new Image());
img
.load(function() {
[...]
}
.attr('src', image_get.children('a').attr('href'));
});
}
_load(0);
Run Code Online (Sandbox Code Playgroud)
^^^ WIP.代码未完成.
是否可以在窗口底部放置背景图像而无需额外的元素或最小高度?
无论网页有多短,我都试图在窗口底部拍摄图像,而不是在身体上.
我的意思是,如果页面长于垂直屏幕分辨率,浏览器允许您滚动到底部,图像将位于底部(页脚背景).
如果页面非常短,可能是屏幕高度的一半,则页脚背景将在半空中"悬挂".我试图让它停留在窗口的底部.
我已尝试过最小高度,但这要求你设置一个足够大的高度,以覆盖访问你网站的人可能反过来创建大空区域的最大分辨率,如果你调整浏览器的大小(或者如果你人们有较小的屏幕).
我尝试将页脚背景设置到body元素上,但它会挂起.将页脚背景设置到html元素上只是在底部给了我一个白色区域,所以我用它作为我的标题背景.
我网站的基本布局是:
<html>
<body>
<div id="header">other elements and header stuff</div>
<div id="main">main content</div>
<div id="footer">other elements and footer stuff</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) jquery ×4
javascript ×3
background ×1
children ×1
css ×1
exists ×1
get ×1
html ×1
html5 ×1
positioning ×1
prop ×1
regex ×1
replace ×1
src ×1
traversal ×1