Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

javascript - 如何从javascript id值填充输入字段值?(How to fill input field value from javascript id value?)

I am having difficulty in getting value from javascript id to the input field.

(我很难从javascript id到输入字段获取价值。)

I tried all the answers available on the platform but not worked.

(我尝试了平台上所有可用的答案,但是没有用。)

while I am getting the value of id="price_div" properly but not in input filed just where id is named.

(虽然我正确地获得了id =“ price_div”的值,但是在输入文件中只是id的命名位置。)

mean id="price_div" has a value when i apply it as like i got value here .

(意思是id =“ price_div”当我应用它时就具有一个值,就像我在这里得到值一样。)

but when i use i don't get value in value filed

(但是当我使用时,我无法从价值中获得价值)

    <div class="title-calc">Approx. price</div>
  <div class="price-total" id="price_div">
    <input type="hidden" name="price" value=""> //Here i want to add price div value
    <span class="currency">$</span><span class="price"></span>
  ask by crypto hacks translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Give id to your input field and then append value through JavaScript

(将id赋予您的输入字段,然后通过JavaScript附加值)

<div class="title-calc">Approx. price</div>
   <div class="price-total" id="price_div">
        <input type="hidden" name="price" id="name" value="">
          <span class="currency">$</span><span class="price"></span>

<script>
var input_value = document.getElementById("price_div").value 
document.getElementById("name").value = input_value
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...