Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
したがって、次のようなスパンがあります。
<span>1</span>
今、私はこのようなことをしたいです(それに加えて)
$(this).next("span").text($(this).next("span").text + 1);
しかし、それはうまくいきません。でも、あなたは私がどこに向かっているのかを見ていますよね?文字列または変数の数値を 1 つ大きくしたい。
どうやってやるの?
$('span').html( parseInt( $('span').html(),10 ) + 1 );
jsFiddleの例
JavaScriptparseInt()関数を試してください。誰かが無効な整数値をスパンに入れている場合のように、エラーの場合を適切に処理するようにしてください。
parseInt()