[英]Javascript syntactic sugar for object value setter
Is there an easy way to do this in one line 有一种简单的方法可以在一行中做到这一点
( node.innerText || node.textContent ) = text
// node = DOM node
// text = string
Obviously the above does not work. 显然以上方法不起作用。
只需使用node.innerText = node.textContent = text
,这是无害的。
一个人可以这样做:
node['textContent' in node? 'textContent' : 'innerText'] = text
首先,不太紧凑的尝试
node.innerText ? node.innerText = text : node.textContent = text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.