我有一个使用 jQuery Mobile 完成的手风琴可折叠,如下图所示。每个手风琴都动态附加了 2 个文本区域和一个按钮。
我已经为按钮设置了点击事件,如下所示。
$('.SaveProj').bind('click',function(){
var mytest = $('#externalNotesMon').val();
alert(mytest);
});
但是警报中显示的值是第一个手风琴的值,而不是点击它的手风琴的值。
有人可以请教我这个问题吗?
请在下面找到我的代码
var projectListStr = "<div data-role='collapsible-set' data-theme='c' data-content-theme='d' id='collabsibleProjectList' data-inset='false'>";
$.each(projectList,function(index, value){
LineOneprojectListStr = "<br/><p class='listP2'><strong>Aktivitet </strong>: "+CheckNullToEmptyString(this.ActivityName)+"</p>";
LineOneprojectListStr += "<br/><p class='listP3'><strong>Händelse/Verksamhet</strong>: "+CheckNullToEmptyString(this.EventName)+"</p>";
projectListStr += "<div data-role='collapsible' class='myset'>";
projectListStr += "<h3>"+this.ProjectName+"<span class='ui-li-count'>"+checkNullToZero(this.Days[i].EventTimant2)+"</span>"+LineOneprojectListStr+"</h3>";
FormStr = "<table align='center'>";
FormStr += "<tr><th>Hours</th><th>Minutes</th></tr>";
var TimeStr = new String((this.Days[i].EventTimant2)).split(".");
FormStr += "<tr><td><input type='number' name='hoursMon' id='hoursMon' value='"+CheckNullEmptyToZero(TimeStr[0])+"' /> </td><td><input type='number' name='minsMon' id='minsMon' value='"+CheckNullEmptyToZero(TimeStr[0])+"' /></td></tr>";
FormStr += "</table>";
FormStr += "<div data-role='fieldcontain' >";
FormStr += "<label for='externalNotesMon'>Fakturatext</label>";
FormStr += "<textarea name='textarea' id='externalNotesMon' style='min-height:120px'>"+CheckNullToEmptyString(this.Days[i].Editext)+"</textarea>";
FormStr += "</div>";
FormStr += "<div data-role='fieldcontain'>";
FormStr += "<label for='internalNotesMon'>Intern Text</label>";
FormStr += "<textarea name='textarea' id='internalNotesMon' style='min-height:120px' >"+CheckNullToEmptyString(this.Days[i].Edit)+"</textarea>";
FormStr += "</div>";
FormStr += " <a href='#' data-icon='check' class='SaveProj' data-theme='g' data-role='button'>Spara</a>"
projectListStr +=FormStr;
projectListStr += "</div>";
});
projectListStr += "</div>";
$('#ProjectList').html(projectListStr);
$('#home2').trigger('create');
$('.SaveProj').bind('click',function(){
var mytest = $('#externalNotesMon').val();
alert(mytest);
});