简体   繁体   English

如何更改使用ajax调用附加的html输入的span值?

[英]How to change span value from a html input which has been appended using ajax call?

I have a modal which is triggered on click and modal data is added by ajax request to my php file. 我有一个单击时触发的模态,并且ajax请求将模态数据添加到我的php文件中。 After the ajax call, when the modal shows,I want the span values in my modal to change simultaneously to the input field of my modal. 在ajax调用之后,当模态显示时,我希望模态中的跨度值同时更改为模态的输入字段。

I have tried this javascript code but it isn't working after the ajax call. 我已经尝试过此javascript代码,但在ajax调用后却无法使用。

$("#j").on("change keypress input", function() {
     $("#total").value( $("#j").val() );
     var a=($(this).val()*2.37).toFixed(2);
     $("#possible").html(a);

});

My modal: 我的模态:

<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> 

My ajax call: 我的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.

相关问题 抓取已从AJAX调用“回波”到PHP的div的html - Grabbing html of div that has been 'echoed' from AJAX call to PHP 从使用AJAX更新的列表框中获取最新值 - Getting the latest value from a listbox which has been updated using AJAX 需要访问 <input> 来自的数据 <form> ,已附加Javascript - Need to access <input> data from a <form>, that has been appended with Javascript 如果数据属性(HTML)=== javascript 中的输入文本,如何更改已写入输入的每个字母的 javascript 颜色? - How can I change color in javascript for each letter which has been written into an input if data attribute(HTML) === input text in javascript? 作法:按一下按钮,将html span(文字)更改为任何输入值 - How to: click button, change html span (text) to whatever input value 如何更改输入文本值已在javascript中设置 - how to change input text value has been set in javascript 如何使用jquery获取输入的附加值 - how to get the appended value of input using jquery 如何实时比较来自 ajax 调用数据库的数据值与 html 输入值 - How compare data value get from ajax call database with html input value in realtime DOM加载后如何使用jQuery从Select输入中获取值 - How do i get value from Select input using jQuery after DOM has been loaded 使用javascript更改输入范围(viceversa),然后将AJAX更新为输入? - Using javascript to change span to input (viceversa) and then AJAX the updated input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM