解决方案 »
- 添加的行 的问题???
- Yahoo!的WEB前端工程师是怎样进行WEB开发工作的
- JS运算符的小问题,速来解决
- 请问如何在ajax提交数据的过程中弹出提示框在取得数据后关闭
- 这个问题是用Hidden解决的吗???????????????????????????
- 请问如何改变一个控件在网页中的位置
- js实现样式转换??
- 怎样用js增加下拉框的选项?
- javascript中如何实现base64_encode??在线等,急啊
- 请问,如何实现这种效果:右击某页面上的某个链接,弹出菜单,该菜单包含有删除等子项,其中删除可删除该链接(对应于数据库中的记录)
- 如何用JS/Jquery定位xml里节点的位置并传到另一个页面?
- 请教,mvc中把页面转化成部分视图后,原来页面从action取得数据,现在从那里取?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i ++) {
links[i].href = 'http://www.' + links[i].title;
links[i].title = '';
}
}
</script>
</head><body>
<a href="#" title="163.com">163.com</a><br />
<a href="#" title="163.com">163.com</a><br />
<a href="#" title="163.com">163.com</a><br />
</body>
</html>
现在多了 ="#" title="
还多一个字符出来了
<a title="163.com">163.com</a>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var arr= document.getElementsByTagName('A');
for (var i = 0;i<arr.length; i++){
arr[i].href=arr[i].href.replace('http://www.','');
}
}
</script>
</head><body>
<a href="http://www.163.com">aaaaa</a><br />
<a href="http://www.163.com" >bbbbbbb</a><br />
<a href="http://www.163.com" >ccccccccccc</a><br />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<a h="163.com">163.com</a>
</body>
<script type="text/javascript">
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i ++) {
links[i].href = 'http://www.' + links[i].h;
}
</script>
</html>
问下.. 缩成上面那样有副作用的吗?
还有整个网站改成这样,对网站性能方面有影响吗?
如果有影响在哪方面呢?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i ++) {
links[i].href = 'http://www.' + links[i].getAttribute('h');
links[i].removeAttribute('h');
}
}
</script>
</head><body>
<a h="163.com">163.com</a><br />
<a h="163.com">163.com</a><br />
<a h="163.com">163.com</a><br />
</body>
</html>
一个页面用了getElementsByTagName和getElementsByTagID超过10个对性能有影响吗?
还有javascript对象的属性可以用变量声明吗?
比如
var a=getElementsByTagName,b=length
看明白了..
客户宽带资源(页面体积过大)造成页面打开速度受影响。
客户硬件资源(CPU,内存)JS使用不当对硬件造成影响。还有个楼上的问题能不能帮忙解决...
还有javascript对象的属性可以用变量声明吗?
比如var a=getElementsByTagName,b=length
我想用a , b 代替属性 然后减少JS的体积....
但是我实验没通过不知道有没办法?
function a(t) {
var obj = document.getElementsByTagName(t);
return obj;
}
var a = a('a');
var b = a.length;
你可以在JS写好后找个混淆器搞搞,压一下体积。关于文件体积的问题,我举个极端的例子:
曾经试过一句CSS,写到页面里,用IE6打开,IE6立即崩溃。就一句话,体积小吧,但是......。
所以,这是个综合平衡逻辑问题,看每个人怎么对待吧。
还有在哪下载呢?还是搜索关键字不够充分?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--************************************************************************-->
<!--* JavaScript Crunchinator Demo *-->
<!--* *-->
<!--* Copyright 2001 by Mike Hall *-->
<!--* Please see http://www.brainjar.com for terms of use. *-->
<!--************************************************************************-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>BrainJar.com: JavaScript Crunchinator Demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link href="/common/default.css" rel="stylesheet" type="text/css" />
<style type="text/css">/* Superfluous stylings for the form. */input, textarea {
background-color: #d0f0f0;
border-color: #00d0d0;
border-width: 2px;
padding: 2px;
scrollbar-base-color: #00d0d0;
}input.button {
background-color: #00d0d0;
border-color: #00d0d0;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
font-weight: bold;
padding: 0px;
width: 5em;
}table {
border-color: #00f0f0 #009090 #009090 #00f0f0;
border-style: solid;
border-width: 2px;
background-color: #00c0c0;
padding: 4px;
}td, th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}th {
background-color: #008080;
border-color: #000000;
border-style: solid;
border-width: 1px;
color: #ffffff;
padding-left: 8px;
padding-right: 8px;
text-align: left;
width: auto;
}</style>
<script type="text/javascript">//<![CDATA[//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************var literalStrings; // For temporary storage of literal strings.function crunch(f) { var input, output;
var i; // Get input script code, process it and display output. f.elements.codeOut.value = "";
f.elements.statusMsg.value = "Working...";
input = f.elements.codeIn.value;
output = input;
f.elements.statusMsg.value = "Replacing literal strings...";
output = replaceLiteralStrings(output);
f.elements.statusMsg.value = "Removing comments...";
output = removeComments(output);
f.elements.statusMsg.value = "Compressing white space...";
output = compressWhiteSpace(output);
f.elements.statusMsg.value = "Combining literal strings...";
output = combineLiteralStrings(output);
f.elements.statusMsg.value = "Restoring literal strings...";
output = restoreLiteralStrings(output);
f.elements.statusMsg.value = "Done.";
f.elements.codeOut.value = output; // Compute sizes. f.elements.sizeIn.value = input.length;
f.elements.sizeOut.value = output.length;
f.elements.sizeDiff.value = input.length - output.length;
if (input.length > 0)
f.elements.pctOut.value = 100 -
Math.round(output.length / input.length * 10000) / 100; return false;
}function replaceLiteralStrings(s) { var i, c, t, lines, escaped, quoteChar, inQuote, literal; literalStrings = new Array();
t = ""; // Split script into individual lines. lines = s.split("\n");
for (i = 0; i < lines.length; i++) { j = 0;
inQuote = false;
while (j <= lines[i].length) {
c = lines[i].charAt(j); // If not already in a string, look for the start of one. if (!inQuote) {
if (c == '"' || c == "'") {
inQuote = true;
escaped = false;
quoteChar = c;
literal = c;
}
else
t += c;
} // Already in a string, look for end and copy characters. else {
if (c == quoteChar && !escaped) {
inQuote = false;
literal += quoteChar;
t += "__" + literalStrings.length + "__";
literalStrings[literalStrings.length] = literal;
}
else if (c == "\\" && !escaped)
escaped = true;
else
escaped = false;
literal += c;
}
j++;
}
t += "\n";
} return t;
}function removeComments(s) { var lines, i, t; // Remove '//' comments from each line. lines = s.split("\n");
t = "";
for (i = 0; i < lines.length; i++)
t += lines[i].replace(/([^\x2f]*)\x2f\x2f.*$/, "$1"); // Replace newline characters with spaces. t = t.replace(/(.*)\n(.*)/g, "$1 $2"); // Remove '/* ... */' comments. lines = t.split("*/");
t = "";
for (i = 0; i < lines.length; i++)
t += lines[i].replace(/(.*)\x2f\x2a(.*)$/g, "$1 "); return t;
}function compressWhiteSpace(s) { // Condense white space. s = s.replace(/\s+/g, " ");
s = s.replace(/^\s(.*)/, "$1");
s = s.replace(/(.*)\s$/, "$1"); // Remove uneccessary white space around operators, braces and parentices. s = s.replace(/\s([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])/g, "$1");
s = s.replace(/([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])\s/g, "$1");
return s;
}function combineLiteralStrings(s) { var i; s = s.replace(/"\+"/g, "");
s = s.replace(/'\+'/g, ""); return s;
}function restoreLiteralStrings(s) { var i; for (i = 0; i < literalStrings.length; i++)
s = s.replace(new RegExp("__" + i + "__"), literalStrings[i]); return s;
}//]]></script>
</head>
<body><div id="demoBox"><h3>JavaScript Crunchinator Demo</h3><p>You can condense JavaScript code using the form below. Just cut and paste
any script code into the text area ed 'Input', press the 'Crunch' button
and the condensed version will appear under 'Output.'</p><p>You can then use the 'Select' button to quickly highlight the output for
easy cut and paste into a new source file.</p><p>Use your browser's <code>View Source</code> option to see the full source
code.</p></div><p></p><form action="" onsubmit="return crunch(this)"><table border="0">
<tr>
<th colspan="3">Input</th>
</tr>
<tr>
<td colspan="3"><textarea name="codeIn" rows="10" cols="80"></textarea></td>
</tr>
<tr>
<td><b>Bytes:</b> <input name="sizeIn" type="text" size="10" disabled="disabled" /></td>
<td><b>Status:</b> <input name="statusMsg" type="text" size="30" disabled="disabled" /></td>
<td style="text-align:right;"><input class="button" type="submit" value="Crunch" /> <input class="button" type="reset" value="Clear" /></td>
</tr>
</table><p></p><table border="0">
<tr>
<th colspan="4">Output</th>
</tr>
<tr>
<td colspan="4"><textarea name="codeOut" rows="10" cols="80"></textarea></td>
</tr>
<tr>
<td><b>Bytes:</b> <input name="sizeOut" type="text" size="10" disabled="disabled" /></td>
<td><b>Saved:</b> <input name="sizeDiff" type="text" size="10" disabled="disabled" /></td>
<td><b>% Saved:</b> <input name="pctOut" type="text" size="10" disabled="disabled" /></td>
<td style="text-align:right;"><input class="button" type="button" value="Select" onclick="this.form.codeOut.select();this.form.codeOut.focus();" /></td>
</tr>
</table></form></body>
</html>
实际文本显示文件体积反而增大了一倍,不知道真实效果是不是也这样?