Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-仅通过引用传递的元素? JS-Bin $(文档).ready(函数(){ var p=$(“#你好”); $(p).文本(“是”); }); hello World_Jquery - Fatal编程技术网

jQuery-仅通过引用传递的元素? JS-Bin $(文档).ready(函数(){ var p=$(“#你好”); $(p).文本(“是”); }); hello World

jQuery-仅通过引用传递的元素? JS-Bin $(文档).ready(函数(){ var p=$(“#你好”); $(p).文本(“是”); }); hello World,jquery,Jquery,上面的代码改变了元素中的文本,但这是否合理? 因为它已经有了两组元素。如果我理解了这个问题(20%的确定性),那么答案是否定的,您不需要第二次将p包装为JQuery对象 <html> <head> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <meta charset=utf-8 /&

上面的代码改变了
元素中的文本,但这是否合理?
因为它已经有了两组
元素。

如果我理解了这个问题(20%的确定性),那么答案是否定的,您不需要第二次将
p
包装为JQuery对象

<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
  <script type="text/javascript">
  $(document).ready(function () {
    var p = $('#hello');
    $(p).text('Yes');
  });
  </script>
</head>
<body>
  <p id="hello">Hello World</p>
</body>
</html>


很好。

如果我理解了这个问题(20%的确定性),答案是否定的,您不需要第二次将
p
包装为JQuery对象

<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
  <script type="text/javascript">
  $(document).ready(function () {
    var p = $('#hello');
    $(p).text('Yes');
  });
  </script>
</head>
<body>
  <p id="hello">Hello World</p>
</body>
</html>


很好。

抱歉@SilverNight。。。你说“因为它已经有两套元素了”是什么意思?我想他有两套
element抱歉@SilverNight。。。你说“因为它已经有两套元素了”是什么意思?我想他有两套元素
$(document).ready(function () {
  $('#hello').text('Yes');
});