如何获取附加的Textarea值?
尝试了这次: get-appended-textare-value但无效
HTML代码:
<div class="request-detail" style="padding-right:10px" ></div>
使用Javascript:
var str = '<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 futura_md_btmedium padding0 hidden reason"><div class="col-xs-12 col-sm-3 col-md-2 col-lg-2 padding0">Reason</div><div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 padding0"><textarea placeholder="Reason to reject the request" style="padding-left:10px;height: 65px;" id="rcon-'+data1.request_id+'" rows="3" cols="5" class="reason-content form-control theme-input theme-input-padding theme-textarea"></textarea><div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-right padding0"><div class="col-xs-12 col-sm-9 col-md-9 col-lg-9 text-left req-msg padding0"></div><div class="col-xs-12 col-sm-3 col-md-3 col-lg-3 text-right padding0"><a class="btn-default add-tour-img reject-myrequest" id="'+data1.request_id+'" href="javascript:;">Send</a></div></div></div></div>'
$('.request-detail').append(str);
$(document).on("click", '.reject-myrequest', function() {
var original_val = this.id;
var reason = $("#rcon-"+original_val).val(); // this returns always empty!
});
答案 0 :(得分:1)
检查data1.request_id
包含的内容,我已将静态值1设置为data1.request_id
并且其工作正常,因此data1.request_id
中应该存在一些问题。
var test = 29;
var str = '<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 futura_md_btmedium padding0 hidden reason"><div class="col-xs-12 col-sm-3 col-md-2 col-lg-2 padding0">Reason</div><div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 padding0"><textarea placeholder="Reason to reject the request" style="padding-left:10px;height: 65px;" id="rcon-'+test+'" rows="3" cols="5" class="reason-content form-control theme-input theme-input-padding theme-textarea"></textarea><div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-right padding0"><div class="col-xs-12 col-sm-9 col-md-9 col-lg-9 text-left req-msg padding0"></div><div class="col-xs-12 col-sm-3 col-md-3 col-lg-3 text-right padding0"><a class="btn-default add-tour-img reject-myrequest" id="'+test+'" href="javascript:;">Send</a></div></div></div></div>'
$('.request-detail').append(str);
$(document).on("click", '.reject-myrequest', function() {
var original_val = this.id;
var reason = $("#rcon-"+original_val).val(); // this returns always empty!
alert(reason);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="request-detail" style="padding-right:10px" ></div>
&#13;