dom

React - how to capture only parent's onClick event and not children

馋奶兔 提交于 2020-05-09 19:22:12
问题 I have part of a React Component that looks like this: var headerElement = someBoolean ? <input/> : 'some string'; return <th onClick={this._onHeaderClick}>{headerElement}</th>; And a click handler for the th element: _onHeaderClick(event) { event.preventDefault(); console.log(event.target); }, I want to capture the th element. It works fine when headerElement is 'some string', but when it is an input element, the input element is the one referenced in the event.target property. What's the

Why use ViewContainerRef over *ngif?

社会主义新天地 提交于 2020-05-09 18:55:29
问题 I could just do <my-awesome-component *ngIf="ConditionToIncludeComponent"></my-awesome-component> But every document on inserting component in dom dynamically is based on ViewContainerRef. I like what it does. But what makes it so special over *ngif? Just point out pros and cons of both. Please. Thanks! 回答1: TLDR; If you don't know what component will be used in a component template when putting together this template use viewContainerRef . If you do know the component beforehand but it can

Angularjs - Inserting directives dynamically to dom element

試著忘記壹切 提交于 2020-04-30 07:34:07
问题 I'm trying to set a directive to my inputs accordingly. So let's say I have this input: <input type="foo" id="myinput" maskvalue> </input> This works fine on my app, the problem is when I try to insert "maskvalue" dynamically using the "setAttribute" it doesn't work, here's what I'm trying to do right now: element = document.getElementById('myinput'); if(element){ element.setAttribute('maskvalue', ""); } This code will successfully insert my directive to the dom element, but will take no

Angularjs - Inserting directives dynamically to dom element

戏子无情 提交于 2020-04-30 07:31:18
问题 I'm trying to set a directive to my inputs accordingly. So let's say I have this input: <input type="foo" id="myinput" maskvalue> </input> This works fine on my app, the problem is when I try to insert "maskvalue" dynamically using the "setAttribute" it doesn't work, here's what I'm trying to do right now: element = document.getElementById('myinput'); if(element){ element.setAttribute('maskvalue', ""); } This code will successfully insert my directive to the dom element, but will take no

How to change the background color of the modified text in a text area

随声附和 提交于 2020-04-21 04:46:48
问题 I want to know how to change the background color or may be color of the text that was modified in a text area. Like suppose, consider a text area with a pre-defined value as "Hello World".. okay? Now if you try to change the text area text to "Hello Universe" so now what i want is Universe to highlighted(may be background color change, or color change or make it bold, anything! I just want to get the modified text to be highlighted that this was changed. I would really appreciate if you try

How to change the background color of the modified text in a text area

独自空忆成欢 提交于 2020-04-21 04:46:20
问题 I want to know how to change the background color or may be color of the text that was modified in a text area. Like suppose, consider a text area with a pre-defined value as "Hello World".. okay? Now if you try to change the text area text to "Hello Universe" so now what i want is Universe to highlighted(may be background color change, or color change or make it bold, anything! I just want to get the modified text to be highlighted that this was changed. I would really appreciate if you try

JS监控DOM的事件(内部插入、移除、修改属性等)!爽!

家住魔仙堡 提交于 2020-04-18 02:35:59
这可不是简单的 onclick、onchange,你对 DOM 进行内部插入、移除、属性修改等均会触发相应事件。 DOM 事件列表: DOMAttrModified DOMAttributeNameChanged DOMCharacterDataModified DOMElementNameChanged DOMNodeInserted DOMNodeInsertedIntoDocument DOMNodeRemoved DOMNodeRemovedFromDocument DOMSubtreeModified 如何用? 像普通绑定事件一样绑定到 DOM 里就可以。 兼容性? 我只测了 Firefox 和 Chrome,其他的没有测,我的项目只需要兼容现代浏览器就可以了。 参考MDN: https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent 参考W3C: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEvent 来源: oschina 链接: https://my.oschina.net/u/988279/blog/491173

DOM Level 2 事件学习总结

瘦欲@ 提交于 2020-04-18 01:51:02
术语 UI events : 用户接口事件,这些事件是由外设(比如鼠标,键盘)触发的。 UI Logical events : 设备无关的用户接口事件,比如focus事件。 Mutation events : 变动事件。这些事件在文档结构发生改变的时候触发。 Capturing : 捕捉,即是事件在目标DOM节点处理之前,由事件目标前驱的事件处理程序处理。 Bubbling : 捕捉,即是事件在目标DOM节点处理之后,由事件目标前驱的事件处理程序处理。 Cancelable : 指示是否阻止DOM实现指定的默认事件处理程序处理。 事件流 基础 每一个Event事件对象都有一个EventTarget属性,这个属性是一个DOM节点的引用。当事件到达目标DOM节点,在这个DOM节点注册的任何事件处理程序都会被触发。事件处理程序的触发顺序是不确定的。 事件流在事件的所有处理程序都执行完成之后才算结束。当然,如果启用了capture(事件捕捉)或者bubbling(事件冒泡)的话,事件流还是可以被修改的。 在事件流的执行过程中,任何事件处理程序抛出异常,整个事件流都将停止。 Event capture(事件捕捉) 事件捕捉的处理流程是从文档树根节点,一直向下处理,直到目标节点才停止。 这里要注意的是,调用Event接口的stopProgagation方法会组织事件流的后续处理。 Event

HTML Collection length is 0 even after DOM has been rendered

回眸只為那壹抹淺笑 提交于 2020-04-16 02:28:12
问题 I am working on SSR React-based application using NextJS . Once DOM has been rendered I need to detect a set of elements visibility in the viewport and once they are visible I need to do something. Now to accomplish that I need the reference to that set of elements which I am taking in componentDidMount lifecycle method, having an understanding that since DOM has been completely rendered I can grab all the elements together and watch them if they are in the viewport or not. Below code is for

HTML Collection length is 0 even after DOM has been rendered

北城余情 提交于 2020-04-16 02:28:09
问题 I am working on SSR React-based application using NextJS . Once DOM has been rendered I need to detect a set of elements visibility in the viewport and once they are visible I need to do something. Now to accomplish that I need the reference to that set of elements which I am taking in componentDidMount lifecycle method, having an understanding that since DOM has been completely rendered I can grab all the elements together and watch them if they are in the viewport or not. Below code is for