リピーターコントロールでテキストボックスの値を見つけるのに苦労しています。ボタンをクリックすると、クリックされたボタンの内側にあるテキストボックスに対応するテキストボックス値を取得する必要があります。
ので、私は持っています :
Textbox1--->Button1でバインドする必要がありますTextBox2---->Button2でバインドします
<span>Question :</span><span>my second content <br /></span><span>Answer : </span><input name="ctl00$MainContent$ctl00$ctl00$TextArea" type="text" id="MainContent_ctl00_TextArea_0" value="6454" />
質問を追加
質問:abcdedf
回答:質問を追加
今、私はクリックされたものを取得するjquery関数を持っています:
$(".addAnswerButton").click(function () {
//var quantityBox = $("#TextArea", $(this).parent());
var tr = $(this).closest("text")
alert(tr.val());
//quantityBox.text = "Hello there";
//var currentValue = quantityBox.val();
$(this).siblings('input[type="text"]').first().val("clicked");
//quantityBox.val(parseInt(currentValue) + 1);
});
私はそれを部分的に動作させました:
$(this).siblings('input[type="text"]').first().val("clicked");
テキストボックスのテキストを設定しましたが、2番目のボタンをクリックしても何も起こりません。
何が間違っているのですか?特定のテキストボックスから値を取得するにはどうすればよいですか?
アップデート
今、私は各コントロールにカスタム属性を追加するソリューションを使用します:
<span>Question :</span>
<span>my second content <br /></span>
<span>Answer : </span>
<input name="ctl00$MainContent$ctl00$ctl00$TextArea" type="text" id="MainContent_ctl00_TextArea_0" value="654" mydataid="2" />
<button id="MainContent_ctl00_answerQuestion_0" Class="addAnswerButton" onclick="Click()" mydataid="2" >Add Question</button><hr /><span>Question :</span><span>abcdedf <br /></span>
<span>Answer : </span><input name="ctl00$MainContent$ctl00$ctl01$TextArea" type="text" mydataid="1" id="MainContent_ctl00_TextArea_1" value="654" />
<button id="MainContent_ctl00_answerQuestion_1" Class="addAnswerButton" onclick="Click()" mydataid="1">Add Question</button>
だから今、私はこれを行うことによってonclickイベントからカスタム属性を取得することができます:
$(".addAnswerButton").click(function() {
var pos = $(this).attr("mydataid");
alert(pos);
// $(this).siblings('input[type="text"]').first().val("clicked");
});
しかし、ボタンとしてsammeカスタム属性名を持つテキストボックスコントロールを取得するにはどうすればよいですか?
アップデート2
70回試行した後、私はついにそれを理解しました(Jqueryでの最初の試行)
解決
$(".addAnswerButton").click(function() {
var pos = $(this).attr("mydataid");
results = $('input[type = "text"][mydataid="'+pos+'"]').first();
alert(results.val());
});
つまり、カスタム属性「name」を取得してから、同じ属性名のテキストボックスを検索しているということです。