我的脚本是这样的:
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并使其正常工作?
答案 0 :(得分:1)
您需要将变量连接到选择器字符串
public async Task<Post> UpdatePostAsync(Post post)
{
// Find (load from the database) the existing post
var existingPost = await dbContext.Posts
.SingleOrDefaultAsync(p => p.Id == post.Id);
// Apply primitive property modifications
dbContext.Entry(existingPost).CurrentValues.SetValues(post);
// Apply many-to-many link modifications
dbContext.Set<PostCategory>().UpdateLinks(
pc => pc.PostId, post.Id,
pc => pc.CategoryId,
post.PostCategories.Select(pc => pc.CategoryId)
);
// Apply all changes to the db
await dbContext.SaveChangesAsync();
return existingPost;
}