如何使用jQuery从字符串中删除最后一个字符?
问题描述:
当我删除 4
时,如何从字符串中删除最后一个字符,例如 123-4-
使用 jQuery 显示 123-
。
How to delete last character from a string for instance in 123-4-
when I delete 4
it should display 123-
using jQuery.
答
您也可以使用普通的javascript
You can also try this in plain javascript
"1234".slice(0,-1)
第二个参数的负数是相对于最后一个字符的偏移量,因此您可以使用-2删除最后两个字符,等等
the negative second parameter is an offset from the last character, so you can use -2 to remove last 2 characters etc