跳至主要内容

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

工作合同 , 离职,工会 相关

转自战法: 平常受主管和同事歧视和欺负,准备把他们告到 Prud'hommes, 所以最近和工会的人走的比较近,学会如何 monter un dossier, 和一些保护自己的方法,特别想跟大家分享。 1. Il faut acter 也就是说,如果同事对你有行为或言语上的 Harcèlement, 当下不要过激,但是一定要给主管发一封邮件。 邮件可以保存下来作为证据。 邮件是 Daté 的,可以记录时间日期。 只要邮件是你发的,对方回不回都无所谓,因为你已经公开表示了不满。 如果是言语骚扰,邮件里一定要引用同事骚扰你的原话。 邮件不要有攻击性,你的请求一定是合理的,但是让对方很难回复。比如我主管不批我的RTT,因为他说“RTT不能半天半天的批”,于是工会的哥们帮我起草了一封邮件,就说“我这个月想提交RTT申请的时候,惊讶地发现四月份的申请被拒了。我不明白,全公司的员工都可以请半天的RTT,为什么我不行?而且你已经批了我三月份两个半天RTT的申请。“ 2. Prise d'acte 如果公司没有很好的履行合同,没有支付工资,同事对你有骚扰,甚至是暴力,等等,你就可以立刻终止你的合同。 这个很厉害,不要轻易使用。因为如果法官判定你的请求不合理,就要赔偿公司 Préavis 的钱。 相关链接: http://vosdroits.service-public.fr/F24409.xhtml http://www.journaldunet.com/management/pratique/contrats/4643/la-prise-d-acte.html http://www.juritravail.com/Actualite/prise-acte-rupture-par-salarie/Id/2136  (prise d'acte 和 démission 的区别) 3. 保存邮件 最好是把你所有的邮件都保存在U盘上,备份在自己家的电脑,以免公司突然给你来个 mise à pied, 你就没办法带走任何证据了。但是千万不要大张旗鼓地做,要不然公司就会怀疑你要做什么对公司不好的事。 4. 最有,一些有用链接: http://vosdroits.service-public.fr/particuliers/N19806.xh