$('.mask').on("click", '.skill-data-box_val p', function () {
var res = $('.skillValue').text();
var res1 = $(this).text()+",";
if(res.indexOf(res1)>-1){
$.alert("已选择");
}else {
res +=res1;
var newStr = res.substring(0,res.length-1);
console.log(newStr);
$('.skillValue').text(res);
}
});
If $('.skillValue').text(res)
The front end shows that the comma at the end is still there (this is for sure)
console.log(newStr)The comma at the end has been removed
But if $('.skillValue').text(newStr)
The front-end display is like this
The same goes for printing
I don’t quite understand. Please give me some advice. I will accept it with an open mind;
Create functions to process strings
That’s it:
Specific modifications
The code is modified to:
Is this okay?:
The main thing is to judge whether
.skillValue
is empty: if it is empty, it means that the added result is the first one, no comma is needed; if it is not empty, it means that there is already a selected value in it, then just add a comma in front of it. .A regular thing