<table>
<tr>
<td class="point"><input type="text"></td>
<td class="point"><input type="text"></td>
<td class="point"><input type="text"></td>
<td class="point"><input type="text"></td>
</tr>
</table>
とHTMLで記述していて、jQueryを下記のように記述しました。
var total;
j$(".point:text").change(function(){
j$(".point:text").each(function(){
var point = j$(this).val();
total = parseInt(point)+total;
});
alert(total);
});
alertで返ってくる結果が「NaN」となります。
どのようにすれば合計値が求められるでしょうか。
やりたいことは「pointクラス」内のテキストフォームの値を合計したいです。
No.1ベストアンサー
- 回答日時:
こんな感じで如何でしょう。
<html>
<head>
<title>テスト</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7 …
<script type='text/javascript'>
$(document).ready(function(){
var total;
$(".point input:text").change(function(){
total=0;
$(".point input:text").each(function(){
var point = $(this).val();
total = parseInt(point)+total;
});
alert(total);
});
});
</script>
</head>
<body>
<table>
<tr>
<td class="point"><input type="text" value="0" /></td>
<td class="point"><input type="text" value="0" /></td>
<td class="point"><input type="text" value="0" /></td>
<td class="point"><input type="text" value="0" /></td>
</tr>
</table>
</body>
</html>
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
このQ&Aを見た人はこんなQ&Aも見ています
-
ちょっと先の未来クイズ第2問
9月9日(月)に発表される「第3回子どもマネー川柳」に入賞する川柳を考えてこちらに投稿してください。
-
フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
あなたが普段思っている「これまだ誰も言ってなかったけど共感されるだろうな」というあるあるを教えてください
-
映画のエンドロール観る派?観ない派?
映画が終わった後、すぐに席を立って帰る方もちらほら見かけます。皆さんはエンドロールの最後まで観ていきますか?
-
海外旅行から帰ってきたら、まず何を食べる?
帰国して1番食べたくなるもの、食べたくなるだろうなと思うもの、皆さんはありますか?
-
天使と悪魔選手権
悪魔がこんなささやきをしていたら、天使のあなたはなんと言って止めますか?
-
テーブル内に表示されている数字の自動計算について
JavaScript
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
- ・ゆるやかでぃべーと タイムマシンを破壊すべきか。
- ・歩いた自慢大会
- ・許せない心理テスト
- ・字面がカッコいい英単語
- ・これ何て呼びますか Part2
- ・人生で一番思い出に残ってる靴
- ・ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
- ・初めて自分の家と他人の家が違う、と意識した時
- ・単二電池
- ・チョコミントアイス
このQ&Aを見た人がよく見るQ&A
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
チェックボックス付きのテーブ...
-
テーブル内のチェックボックス...
-
JavaScriptの「.querySelectorA...
-
同一nameの input type="text"...
-
フォーム2度押禁止ボタンscript...
-
xml+xslt変換後のstyle操作
-
JavaScriptでリストボックスに...
-
formで項目を連結したい
-
ラジオボタンを一括で操作する...
-
ラジオボタンが選択されたらテ...
-
VBSでの自動ログイン
-
return trueとreturn falseの用...
-
1つのページにformを2つ設置。2...
-
クリックさせたいが、click()が...
-
プルダウン選択を変更すると、...
-
新しくフォルダを作成したい
-
onClickとsubmitの処理順序
-
ラジオボタンと連動して文字列...
-
javascriptで二重送信防止
-
チェックボックスのON/OFFでVal...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
チェックボックス付きのテーブ...
-
JavaScriptの「.querySelectorA...
-
formで項目を連結したい
-
Formのシリアライズができない
-
画面表示とともにtableの指定の...
-
文字数を数える際に空白、改行...
-
クリックしたラジオボタンの行...
-
ラジオボタンを一括で操作する...
-
画面の2重起動をチェックする...
-
ラジオボタンとテキストボック...
-
Javascriptの電卓で最初の何も...
-
入力チェックの外部スクリプト...
-
JavaScriptによる自動計算フォーム
-
複数のselect値で1つも選択され...
-
javascriptで表(テーブル)の自...
-
jQueryで合計を出したい
-
localStorageでのcheckbox制御
-
JavaScriptで、コピーボタンを...
-
Javascriptで自動的に計算する...
-
WEBフォーム(asp)から画像デ...
おすすめ情報