我知道这个问题可能听起来有点疯狂,但我认为也许有人可能想出一个聪明的主意:
想象一下,您在一个HTML页面上有1000个缩略图.
图像大小约为5-10 kb.
有没有办法在单个请求中加载所有图像?不知何故将所有图像压缩成一个文件......
或者您对该主题有任何其他建议吗?
我已经知道的其他选择:
CSS sprites
懒加载
设置过期标头
下载不同主机名的图像
有人可以告诉我为什么下面的代码不起作用.它应该提醒它.但即使字段为空,它也会在之后返回true.
<form id="theform" method="post" action="mailme.php">
<input id="field1" name="a" value="field1" type="text" />
<input id="field2" name="b" value="field2" type="text" />
<input id="field3" name="c" value="field3" type="text" />
<input id="field4" name="d" value="field4" type="text" />
<input type="submit" />
</form>
<script>
$('#theform').submit(function(){
$('#theform input[type=text]').each(function(n,element){
if ($(element).val()=='') {
alert('The ' + element.id+' must have a value');
return false;
}
});
return true;
});
</script>
Run Code Online (Sandbox Code Playgroud)