V2EX / 技术 / JavaScript
- http://mjijackson.com/shadowbox/
http://www.huddletogether.com/projects/lightbox2/... 1 篇回复 | 参与讨论 | 蓝色梦幻 | | | | | | | | | 
<style type="text/css">
.orig {
display: none;
}
</style>
你想要改变把他的display属性由none改为inline。
解决办法: 在IE里:
document.styleSheets[0].rules[0].style.display = "inline";
在firefox里:
document.styleSheets[0].cssRules[0].style.display = "inline";
讨论: 可以做一个函数来搜索特定名字的style对象:
function getstyle(sname) {
for (var i=0;i<document.styleSheets.length;i++) {
var rules;
if (document.styleSheets[i].cssRules) {
rules = document.styleSheets[i].cssRules;
} else {
rules = document.styleSheets[i].rules;
}
for (var j=0;j<rules.length;j++) {
if (rules[j].selectorText == sname) {
return rules[j].style;
}
}
}
}
然后只要:
getstyle(".orig").display = "inline";
就可以了。... 0 篇回复 | 参与讨论 | 蓝色梦幻 | | | | | | | | | 
- Sortable.create
用此方法可以初始化一个可排序对象。
表达式:
Sortable.create('id_of_container',[options]);
可选项:
Option Default Description
tag li 设置一个可被Sortable的标签种类(应包含在表达式指定的容器中),在UL或者OL容器中,LI标签是默认值。
only (none) 此选项将约束指定的CSS class所在的对象才能够加载Sortable,你可以指定一个单独的class名称或者一个CSS class所组成的字符串数组。
overlap vertical 该选项有2个可选值,‘vertical’ 或者 ‘horizontal’。 对于浮动对象或者水平列表,选择‘horizontal’。 竖直的列表对象应该选择 ‘vertical’。
constraint vertical 约束可拖曳的对象的移动方向。可选值为‘vertical’ 或者 ‘horizontal’。
containment () 允许在多个Sortable对象之间进行DragAndDrop,给出一个或者多个Sortable对象的ID或ID字符组成的数组来指定发生 DragAndDrop的对象。该行为发生的要点是:所有指定的ID,其容器必定要加载Sortable.create方法。(注意:如果想让拖曳的目的容器仍然具有排序功能,那在containment中必须指定好自生容器的id。)
format 干嘛的?我不是很清楚。
handle (none) 和Draggable中的选项一样,选择一个对象作为拖曳出发之处。(ver 1.8.1没用?)
hoverclass (none) 为创建Droppables的对象指定一个hover时的样式。
ghosting false 在拖曳时在原地产生一个克隆的拖曳对象。(ver 1.8.1中该选项在IE下有bug,期待新版本)
dropOnEmpty false 如果设置为true时,这个sortable的容器会变成一个可Droppable的对象,进而该容器可以接受任何可拖曳且被容许Drop in的对象加入该容器。
scroll (none) 一大串东东,暂不理解,请看E文:When the sortable is contained in an element with style overflow:scroll, this value can be set to the ID of that container (or the container’s DOM object). The scroll position of the container will now move along when the sortable is dragged out of the viewable area. The container must have overflow:scroll set to include scroll bars. Does not yet work for scrolling the entire document. To get this to work correctly, include this line in your code before creating the sortable: Position.includeScrollOffsets = true; Update: Scrolling the whole document does work (at least on IE7 and Firefox). Use scroll: window
scrollSensitivity 20 Will start scrolling when element is x pixels from the bottom, where x is the scrollSensitivity.
scrollSpeed 15 Will scroll the element in increments of scrollSpeed pixels.
tree false If true, sets sortable functionality to elements listed in treeTag(点解?)
treeTag ul The element type tree nodes are contained in.(点解,too?)
回调函数:
Callback Description
onChange 当拖曳引起排序改变时该事件会被触发。当你将一个对象拖曳到另一个Sortable对象中,则该回调函数会在两个Sortable中各自触发一次。该函数默认接受参数为该被拖曳的对象。
onUpdate 当一个拖曳完成并且Sortable的排序被改变时,该事件触发。同样的,如果将被拖曳对象从一个Sortable拉到另一个Sortable时,该回调函数将在各自的Sortable中触发。默认接受的参数为该Sortable容器。
注意:
有一点非常重要,在创建Sortable的时候允许的容器对象应该为块对象,当时基于当前浏览器的技术限制,table、tbody、tr等块对象将不被支持。
在一个嵌套在table中的Sortable对象将不能在IE浏览器下非常顺利的工作,除非为该table赋予一个position:relative的CSS属性。总之啦,尽量不要将Sortalbe容器放到table中就安拉!
如果你想生成一个带滚动条的Sortable对象,那么最好在该Sortable外嵌套一个div对象,并为该对象设置滚动样式。在IE下你还得做的一个工作就是要为该div附加一个position:relative的CSS属性。
http://jiachen.blogbus.com/logs/16939581.html... 0 篇回复 | 参与讨论 | bluedream | | | | | | | | | 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<script type="text/javascript" language="javascript">
function setRadioValue(name,value){
var nameTemp = document.getElementsByName(name);
for (var i=0; i<nameTemp.length;i++){
if (nameTemp[i].value == value){
nameTemp[i].checked = true;
}
}
}
function getRadioValue(name){
var nameTemp = document.getElementsByName(name);
for (var i=0; i<nameTemp.length;i++){
if (nameTemp[i].checked == true){
alert(nameTemp[i].value);
return nameTemp[i].value;
}
}
}
</script>
<body onload="setRadioValue('radioTest','3')">
<table>
<tr>
<td>
<p>测试Radio<br>
-----设置初始值以及获取当前值------
<br>
<input type="radio" name="radioTest" value="1" onclick="getRadioValue(this.name)"/>1
<input type="radio" name="radioTest" value="2" onclick="getRadioValue(this.name)"/>2
<input type="radio" name="radioTest" value="3" onclick="getRadioValue(this.name)"/>3
<input type="radio" name="radioTest" value="4" onclick="getRadioValue(this.name)"/>4
<input type="radio" name="radioTest" value="5" onclick="getRadioValue(this.name)"/>5
</td>
</tr>
</table>
</body>
</html>
... 0 篇回复 | 参与讨论 | 蓝色梦幻 | | | | | | | | | 
- http://www.kenengba.com/post/432.html... 0 篇回复 | 参与讨论 | 蓝色梦幻 |
| | | | | | | | 
- <script language="JavaScript">
//图片按比例缩放
var flag=false;
function JeffImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
ImgD.title="我本来长的很魁梧的。但是为了不影响站容,我把自己变小了。欲知我真面目,请点击我!";
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
ImgD.title="我本来长的很魁梧的。但是为了不影响站容,我把自己变小了。欲知我真面目,请点击我!";
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
</script>
<a href="图片地址" target="_blank"><img src="图片地址" width="180" height="100" border="0" onload="javascript:JeffImage(this,最大宽度,最大高度);"></a>
代码说明:
width="180" height="110" 注意这里最好限定。如果不限定,加载图时,图片会成原大,然后再缩小。这个过程,如果图大了很难看的。
javascript:JeffImage(this,最大宽度,最大高度),图片没有达到最大宽度或者最大高度时,不缩小。... 0 篇回复 | 参与讨论 | 蓝色梦幻 | | | | | | | | | 
- 以下以 ie 代替 internet explorer,以 mf 代替 mozzila firefox
1. document.form.item 问题
(1)现有问题:
现有代码中存在许多 document.formname.item("itemname") 这样的语句,不能在 mf 下运行
(2)解决方法:
改用 document.formname.elements["elementname"]
(3)其它
参见 2
2. 集合类对象问题
(1)现有问题:
现有代码中许多集合类对象取用时使用 (),ie 能接受,mf 不能。
(2)解决方法:
改用 [] 作为下标运算。如:document.forms("formname") 改为 document.forms["formname"]。
又如:document.getelementsbyname("inputname")(1) 改为 document.getelementsbyname("inputname")[1]
(3)其它
3. window.event
(1)现有问题:
使用 window.event 无法在 mf 上运行
(2)解决方法:
mf 的 event 只能在事件发生的现场使用,此问题暂无法解决。可以这样变通:
原代码(可在ie中运行):
<input type="button" name="somebutton" value="提交" onclick="javascript:gotosubmit()"/>
...
<script language="javascript">
function gotosubmit() {
...
alert(window.event); // use window.event
...
}
</script>
新代码(可在ie和mf中运行):
<input type="button" name="somebutton" value="提交" onclick="javascript:gotosubmit(event)"/>
...
<script language="javascript">
function gotosubmit(evt) {
evt = evt ? evt : (window.event ? window.event : null);
...
alert(evt); // use evt
...
}
</script>
此外,如果新代码中第一行不改,与老代码一样的话(即 gotosubmit 调用没有给参数),则仍然只能在ie中运行,但不会出错。所以,这种方案 tpl 部分仍与老代码兼容。
4. html 对象的 id 作为对象名的问题
(1)现有问题
在 ie 中,html 对象的 id 可以作为 document 的下属对象变量名直接使用。在 mf 中不能。
(2)解决方法
用 getelementbyid("idname") 代替 idname 作为对象变量使用。
5. 用idname字符串取得对象的问题
(1)现有问题
在ie中,利用 eval(idname) 可以取得 id 为 idname 的 html 对象,在mf 中不能。
(2)解决方法
用 getelementbyid(idname) 代替 eval(idname)。
6. 变量名与某 html 对象 id 相同的问题
(1)现有问题
在 mf 中,因为对象 id 不作为 html 对象的名称,所以可以使用与 html 对象 id 相同的变量名,ie 中不能。
(2)解决方法
在声明变量时,一律加上 var ,以避免歧义,这样在 ie 中亦可正常运行。
此外,最好不要取与 html 对象 id 相同的变量名,以减少错误。
(3)其它
参见 问题4
7. event.x 与 event.y 问题
(1)现有问题
在ie 中,event 对象有 x, y 属性,mf中没有。
(2)解决方法
在mf中,与event.x 等效的是 event.pagex。但event.pagex ie中没有。
故采用 event.clientx 代替 event.x。在ie 中也有这个变量。
event.clientx 与 event.pagex 有微妙的差别(当整个页面有滚动条的时候),不过大多数时候是等效的。
如果要完全一样,可以稍麻烦些:
mx = event.x ? event.x : event.pagex;
然后用 mx 代替 event.x
(3)其它
event.layerx 在 ie 与 mf 中都有,具体意义有无差别尚未试验。
8. 关于frame
(1)现有问题
在 ie中 可以用window.testframe取得该frame,mf中不行
(2)解决方法
在frame的使用方面mf和ie的最主要的区别是:
如果在frame标签中书写了以下属性:
<frame src="xx.htm" id="frameid" name="framename" />
那么ie可以通过id或者name访问这个frame对应的window对象
而mf只可以通过name来访问这个frame对应的window对象
例如如果上述frame标签写在最上层的window里面的htm里面,那么可以这样访问
ie: window.top.frameid或者window.top.framename来访问这个window对象
mf: 只能这样window.top.framename来访问这个window对象
另外,在mf和ie中都可以使用window.top.document.getelementbyid("frameid")来访问frame标签
并且可以通过window.top.document.getelementbyid("testframe").src = 'xx.htm'来切换frame的内容
也都可以通过window.top.framename.location = 'xx.htm'来切换frame的内容
关于frame和window的描述可以参见bbs的‘window与frame’文章
以及/test/js/test_frame/目录下面的测试
----adun 2004.12.09修改
9. 在mf中,自己定义的属性必须getattribute()取得
10.在mf中没有 parentelement parement.children 而用
parentnode parentnode.childnodes
childnodes的下标的含义在ie和mf中不同,mf使用dom规范,childnodes中会插入空白文本节点。
一般可以通过node.getelementsbytagname()来回避这个问题。
当html中节点缺失时,ie和mf对parentnode的解释不同,例如
<form>
<table>
<input/>
</table>
</form>
mf中input.parentnode的值为form, 而ie中input.parentnode的值为空节点
mf中节点没有removenode方法,必须使用如下方法 node.parentnode.removechild(node)
11.const 问题
(1)现有问题:
在 ie 中不能使用 const 关键字。如 const constvar = 32; 在ie中这是语法错误。
(2)解决方法:
不使用 const ,以 var 代替。
12. body 对象
mf的body在body标签没有被浏览器完全读入之前就存在,而ie则必须在body完全被读入之后才存在
13. url encoding
在js中如果书写url就直接写&不要写&例如var url = 'xx.jsp?objectname=xx&objectevent=xxx';
frm.action = url那么很有可能url不会被正常显示以至于参数没有正确的传到服务器
一般会服务器报错参数没有找到
当然如果是在tpl中例外,因为tpl中符合xml规范,要求&书写为&
一般mf无法识别js中的&
14. nodename 和 tagname 问题
(1)现有问题:
在mf中,所有节点均有 nodename 值,但 textnode 没有 tagname 值。在 ie 中,nodename 的使用好象
有问题(具体情况没有测试,但我的ie已经死了好几次)。
(2)解决方法:
使用 tagname,但应检测其是否为空。
15. 元素属性
ie下 input.type属性为只读,但是mf下可以修改
16. document.getelementsbyname() 和 document.all[name] 的问题
(1)现有问题:
在 ie 中,getelementsbyname()、document.all[name] 均不能用来取得 div 元素(是否还有其它不能取的元素还不知道)。... 0 篇回复 | 参与讨论 | 蓝色梦幻 | | | | | | | | |  创建新主题 | RSS | NORMAL Mode |