我有一个小脚本。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$( "p" ).first().replaceWith("Hello world!");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Replace the first p element with new text</button>
这会将第一个
中的内容替换为“Hello world!”。
我用 2 个 jquery 脚本得到了相同的结果。
1) ( "p:first" )
2) ("p").first()
这两个脚本之间的确切区别是什么。
最佳答案
根据性能测试found here第二种方式 ($("p").first();
) 速度要快得多。
关于javascript - ( "p:first") 与 ("p").first() Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20628525/