gpt4 book ai didi

javascript - jquery函数中的目标AJAX id

转载 作者:行者123 更新时间:2023-12-03 01:48:34 25 4
gpt4 key购买 nike

我的脚本是这样的:

function comtype($id, $comtype, $vendor){
//get the input value
$.ajax({
//the url to send the data to
url: "example.com/updatedb.php",
//the data to send to
data: {id: $id, comtype: $comtype, vendor: $vendor},
//type. for eg: GET, POST
type: "POST",
//on success
success: function(data){
console.log("***********Success***************"); //You can remove here
console.log(data); //You can remove here
(function($) {
jQuery.fn.extend({
prependClass: function(newClasses) {
return this.each(function() {
var currentClasses = $(this).prop("class");
$(this).removeClass(currentClasses).addClass(newClasses + " " + currentClasses);
});
}
});

})(jQuery);
$("#mycontent a.half").removeClass("half").prependClass("paid");
//$("#mycontent a.pending").removeClass("pending").prependClass("half");

},
//on error
error: function(){
console.log("***********Error***************"); //You can remove here
console.log(data); //You can remove here
}
});
}

对于这个特定的行:

$("#mycontent a.half").removeClass("half").prependClass("paid");

我希望能够定位使用该 id 的确切类。

例如,我有几个类的链接,例如:

class="half first4234"
class="half first8293"
class="half first9221"

我尝试过以下方法:

$("#mycontent a.half first$id").removeClass("half").prependClass("paid");

这会引发以下错误:

Error: Syntax error, unrecognized expression: #mycontent a.half first$id

如何获取 $id 并使其正常工作?

最佳答案

您需要将变量连接到选择器字符串

$("#mycontent a.half first" + $id)

关于javascript - jquery函数中的目标AJAX id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50519350/

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