我注意到以下几点:
<div id='myDiv'>...</div>
<script>
myDiv.style.color = 'red'; // I can access the object.
<script>
Run Code Online (Sandbox Code Playgroud)
在实现这一点之前,我总是使用以下内容:
var x = document.getElementById('myDiv');
x.style.color = 'red';
Run Code Online (Sandbox Code Playgroud)
我很迷惑.第二种方法有什么意义?第一种方法总是有效吗?
<a href="url">A link</a>
$.each($('a'), function(index,value){
alert (value)
});
Run Code Online (Sandbox Code Playgroud)
它会警告:url.为什么会这样?