簡體   English   中英

如何更改使用ajax調用附加的html輸入的span值?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM