跳至主要内容

java script 笔记

检查 element type :
设我们有:



type="radio" name="q1" value="1125" />1125
type="radio" name="q1" value="375" />375
type="radio" name="q1" value="178" />178
type="radio" name="q1" value="75" />75
type="radio" name="q1" value="45" />45
type="text" name="q2" value="" />

window.document.forms[0].q1.type=undefined
window.document.forms[0].q1[0].type=radio
window.document.forms[0].q1[1].type=text
window.document.forms[0].q2.type =text
待验证

关于 nodeType
http://javascript.gakaa.com/node-nodetype.aspx 英文
http://fr.selfhtml.org/javascript/objets/node.htm#node_type 法文

Object Oriented Programming in JavaScript 面向对象
http://mckoss.com/jscript/object.htm

Introduction to Forms 简介
http://www.quirksmode.org/js/forms.html#stext


另:
input 是node名字而不是type,所以可以用getelementByTagName来获得,
问:现在的问题是如何获得特定form下的input,而不是整个document下的。
答:document.forms[0].getElementsByTagName("input"),经测试 可行


问:现在可以找到所有的input tag 和其他类型的tag,比如说checkbox,selection 之类,但是无法找到其相应的attribute,因为很可能那东西根本不在tag里。怎么办?


问:能否通过一个element和并以他的边界为基点,找到离他边界最近的attribute,
答:可以,但是很困难。同样需要先建立attribute list 来进行访问,实际上, 必须先取得所有需要匹配的attribute,然后你用边界为基点一圈一圈扩大来寻找匹配的attribute,但是这个实际上还不如直接建立对,并计算他们的相关度来的划算。
补充:也不尽然,完全可以认为是一个等速螺线以设定的element 边界为包络线,什么时候碰到另外一个element 或者是attribute,那么就计算他们之间的“面积距离”,找到最有可能的attribute,这个比一一对应是不是会强一点?

问:可是这个“碰”怎么定义?
答:即当这个等速螺线的终点落在任意一个attribute或者element的包络线之内。

问:这样是不是需要每时每刻都判断,并且对所有的element, attribute都需要做一个判断器,并且并行?这个太浪费资源了。

另外一个办法:
假设:是否可以把ie的页面认为是一个画布,因为所有的element ,attribute其实都不可能太小(太小用户也会看不见),所以,假设把这个画布用10*10的点阵来表示,每个10*10的小方块认为是一个点,这个点或者属于某个element,或者不属于。如果它同时属于两个以上的element,那就认为他谁也不属于。所以我们可以把整个画布看成是一个100*50的点阵,每个点是一个object,它有一个指针,指向它属于的那个element。ok,现在这个问题变得简单了,我以某个element的那一堆点为中心,扩大它的范围,鉴于所有的element, attribute都是正方形,并且斜对角的对应关系很少见,也没有prio,所以:存在一个m*n的element,其起始点位置为x0,y0, 那么关联区域为:四个:
x0-m,y0 => x0,y0+n,
...
...
...

如上图所示,然后确认是否有点的指针为非空,找到非空的指针所指的element,
此方法的好处是不用建立一个attribute,element的距离表。
问:attribute如何定义?
答:通过研究dom tree的内容发现,所有分离的text都会被认为是分散的node, 这一点在firebug里看得很清楚,chrome自带的工具显示的并不是很好。 所以可以通过遍历所有的texte node来找到所有的attribute list

so : 需要两个list,一个是attribute list, 一个是 element list,然后计算 对之间的距离

prerequisite: 可以设置一些前提条件,基于html tag structure的。
问: 这些先决条件如何设置
答:可以通过研究html 语言来设置.

问:先决条件的list
答:待验证:
1.如果attribute和element有一个共同的parentNode,那么有一定的优先级
2.checkbox和radiobox如果是同名,那么一定是关联的。

评论

  1. 今天倒霉了,和别出租车撞了,我赔钱了。5555555555

    回复删除
  2. 呵呵,真可怜。我还不会开车呢

    回复删除

发表评论

此博客中的热门博文

jquery on 的问题

return false  from  within a jQuery event handler  is effectively the same as calling both  e.preventDefault and  e.stopPropagation  on the passed  jQuery.Event object. e.preventDefault()  will prevent the default event from occuring,  e.stopPropagation()  will prevent the evet from bubbling up and  return false  will do both. Note that this behaviour differs from  normal  (non-jQuery) event handlers, in which, notably,  return false   does  not  stop the event from bubbling up . 所以on前半部分的selector必须是静态的。

chrome extension Error: attempting to use a disconnected prot object

if you get this error: Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:236 chromeHidden.Port.dispatchOnDisconnect miscellaneous_bindings:236 Uncaught Error: Attempting to use a disconnected port object miscellaneous_bindings:58 PortImpl.postMessage miscellaneous_bindings:58 responseCallback miscellaneous_bindings:143 xhr.onreadystatechange That means you have make some mistake as this discussed: This is caused when a connection get closed. For example if you open a tab that has the content_script injected, it opens a connection, the tab is closed, and then the background_page tries to pass a message. It will fail because the tab is no longer active to receive the message. In your case I would guess that as tabs close and new tabs open you are attempting to post messages with the old tabId instead of creating a new connection to the new tab. I would recommend reading through the  long-lived connections s

记得很久以前,不知道是在跟谁发感慨,久到好像是上大学时候的事了。我说,我流过很多眼泪,看电影流眼泪,看小说流眼泪,听别人的故事留言了,听歌的时候流眼泪,晚上一个人的时候独自流眼泪。我似乎是一个是一个太不像男人的男人。可是我又说,这些眼泪都是为自己流的。于是我也问对面那个人,(嗯,我也记不起她是谁了): "你为别人流过眼泪么?",居然没有回答我. 也许看见这篇文章的人也不相信,但是我真的想问你一句,你为别人流过眼泪么?真真正正的是为别人的,不是可怜自己,不是觉得别人可怜而让自己也感到了可怜,仅仅是为了别人而悲伤,有过么?如果真的有,我想那也许才是爱吧。 也许您会觉得奇怪,这和爱有什么关系?是啊,流眼泪就是爱么?我们因为悲伤而流泪,流泪是因为,爱别离,求不得,这些的主体是什么?是自己。 我们都是爱自己的,只是99%的人是吧。所以我们流泪了,因为我们的那些种种原因,我们很少会因为别人“求不得,爱别离”而流泪吧。也许说,那又不是自己,对呀,你爱自己,你又不爱她,何苦要为她流这种泪? 我不是一个宽容的人,我也不是一个豁达的人,这是我一生的缺点。我们会为了爱去宽容,我们会因为爱而变的豁达,也许,这是因为我从来都没有真正的爱过谁吧,甚至,连自己。嘿,我现在都开始疑惑,我真的爱过你么,如果是,我为什么都没有宽容和豁达呢?