onkeyup 文本框,从 span javascript 获取值

onkeyup textbox, get value from span javascript

如何使用动态 ID 从跨度中获取值并在文本输入中显示?

我有这个span id

<span id="unitCost{{$data->product_id}}">700</span>

    **Onkeyup I want to get the span data.**
   
<input type="number" class="form-control total_cost " id="productId{{$data->product_id}}" onkeyup="calculate({{$data->product_id}})" min="0">

Javascript 我试过了

   calculate = function(id)
{
 var qty = document.getElementById('unitCost'+id).value;
    alert (qty);
}

使用innerText代替value

calculate = function(id)
{
 var qty = document.getElementById('unitCost'+id).innerText;
    alert (qty);
}