最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamically change value of input textField - Stack Overflow

programmeradmin1浏览0评论

I have a html block as follows with an input textfield that updates the entire application when it is manually edited.

How can I dynamically target and change this input text field? In the following this would be value="2"

    <my-attribute param="Count" min="0" max="100" step="1">
        <span id="label">Count</span><span id="input">
<dat-input-number id="input" value="2" step="1" min="0" max="100">
         <div id="blocker" on-dblclick="" style="width: 152px; height: 15px;"></div>
        <input id="number" type="text" on-keydown="">       
      </dat-input-number></span>
      </my-attribute>

I have a html block as follows with an input textfield that updates the entire application when it is manually edited.

How can I dynamically target and change this input text field? In the following this would be value="2"

    <my-attribute param="Count" min="0" max="100" step="1">
        <span id="label">Count</span><span id="input">
<dat-input-number id="input" value="2" step="1" min="0" max="100">
         <div id="blocker" on-dblclick="" style="width: 152px; height: 15px;"></div>
        <input id="number" type="text" on-keydown="">       
      </dat-input-number></span>
      </my-attribute>
Share Improve this question asked Dec 10, 2013 at 23:32 user2005121user2005121 4371 gold badge6 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4
<script>
document.getElementById('number').value = "yourValueHere";
</script>

Oh, and don't forget to close your <input id="number" type="text" on-keydown=""> with an </input>

<script>
    var theInput = document.getElementById('input');
    theInput.value = '5';
</script>

Working demo here

Note: This is super trivial and I have no doubt that you could have found enough knowledge through a Google search to attempt this on your own. :)

发布评论

评论列表(0)

  1. 暂无评论