[英]How to change span value from a html input which has been appended using ajax call?
我有一个单击时触发的模态,并且ajax请求将模态数据添加到我的php文件中。 在ajax调用之后,当模态显示时,我希望模态中的跨度值同时更改为模态的输入字段。
我已经尝试过此javascript代码,但在ajax调用后却无法使用。
$("#j").on("change keypress input", function() {
$("#total").value( $("#j").val() );
var a=($(this).val()*2.37).toFixed(2);
$("#possible").html(a);
});
我的模态:
<div class="modal-body">
<div id="modal-body" class='form-row has-danger border-bottom mb-30'>
</div>
<div class='col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12 border-bottom form-row mt-15 mb-10'>
<div class='col-xl-8 col-lg-8 col-md-8 col-sm-8 col-xs-8 text-left'>
<strong>Total Jobs</strong>
</div>
<div class='col-xl-4 col-lg-4 col-md-4 col-sm-4 col-xs-4 text-right'>
<strong><span id='total'></span></strong> //want to change value of this based on input field added from php page
</div>
</div>
<div class='col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12 form-row '>
<div class='col-xl-8 col-lg-8 col-md-8 col-sm-8 col-xs-8 text-left'>
<strong>Possible Jobs</strong>
</div>
<div class='col-xl-4 col-lg-4 col-md-4 col-sm-4 col-xs-4 text-right'>
<strong><span id='possible'></span></strong> //want to change value of this based on input field added from php page
</div>
</div>
</div>
我的ajax电话:
function job(job_id) {
$.ajax({
url : "job.php", //this is my php file where echo for the modal happens
type : "post",
dataType:"text",
data : {
stake_id: bet_id
},
success : function (a){
$('#modal-body').html(a);//adding echo part to my modal
$('#RequestModal').modal('show');
}
}
我没有全部了解,但我注意到您正在尝试通过val()函数获取span的值,而应使用html()或text()代替,以获取该值并在需要的任何地方使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.