gpt4 book ai didi

jquery - 函数内部的参数如何工作?

转载 作者:行者123 更新时间:2023-12-01 00:14:35 27 4
gpt4 key购买 nike

html

<p>This is a <b>bold</b> paragraph.</p>
<button>Add</button>

jquery

$("button").click(function(){
$("p").text(function(i,origText){
return "Old text: " + origText + " New text: Hello world! (index: " + i + ")";
});
});

我想知道 origText 没有在函数外部调用,但它正在返回值。怎么办?

demo

最佳答案

As docs says

function(index, text)

A function returning the text content to set. Receives the index position of the element in the set and the old text value as arguments.

How does jQuery’s .text() work, internally?

关于jquery - 函数内部的参数如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17699185/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com