0

当我找到程序 Donor Refund 时,我需要访问具有部分 id “clinic_base_fee_fresh”的输入文本框

在此处输入图像描述

$("th[id*='programme_details']").each(function() {
                    var programeName = $(this).html();    
                    if(programeName.indexOf('Donor') > -1){
                        // find the first input with clinic_base_fee_fresh ??                       
                        if($('#programme_details > input:first').attr('id') == 'clinic_base_fee_fresh')
                        {
                            // then select that text box
                            // apply the value "set"
                            //??
                            $('that textbox').val(12);
                        }                       
                        console.log(programeName);
                    }                   
                });
4

2 回答 2

1

你只有第一行的答案

$("#programme_details").each(function() {
                var programeName = $(this).html();    
                if(programeName.indexOf('Donor') > -1){
                    // find the first input with clinic_base_fee_fresh ?? 
                    var txtBox = $('[id*=clinic_base_fee_fresh]', $(this));
                    if(txtBox)
                    {
                        // then select that text box
                        // apply the value "set"
                        //??
                        txtBox.val(12);
                    }                       
                    console.log(programeName);
                }                   
            });
于 2021-08-18T11:44:21.280 回答
0

// The easiest way is just to select by id, 
// the list will be built in order that it is in the HTML,
// so you can just use this to get the first element:
var html = $('[id*=clinic_base_fee_fresh]')[0];

// However this just gives the HTML, we can still use it though by changing the property
html.value = 'c';

// FOR DEMO REASONS I TIME OUT RIGHT HERE
setTimeout(function(){

  // To get the jQuery object to use jQuery function use this:
  var jquery = $('#programme_details input').first();

  // Now we can use jQuery function val()
  jquery.val('d')

}, 1500);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="programme_details">
  <input id="1_clinic_base_fee_fresh" value="a"/>
  <input id="2_clinic_base_fee_fresh" value="b"/>
</div>

文档:

值()

第一的()

于 2021-08-18T14:53:25.787 回答