Используйте document.getElementById("id").value = "yourvalue"
или document.getElementsByClassName("yourclass")[index].value = "yourvalue"
.
Используя id
:
Enter text to be the value of the second input field:<br/>
<input type="text" id="text"/>
<br/>
<input type="button" onClick="changeValue()" value="Change Value"/>
<p/>
<input type="text" id="result"/>
<script>
function changeValue(){
document.getElementById("result").value = document.getElementById("text").value;
}
</script>
Используя class
:
Enter text to be the value of the second input field:<br/>
<input type="text" class="text"/>
<br/>
<input type="button" onClick="changeValue()" value="Change Value"/>
<p/>
<input type="text" class="result"/>
<script>
function changeValue(){
document.getElementsByClassName("result")[0].value = document.getElementsByClassName("text")[0].value;
}
</script>
Для вашего кода:
Enter text to be the value of the search input field:<br/>
<input type="text" class="text"/>
<br/>
<input type="button" onClick="changeValue()" value="Change Value"/>
<p/>
<script>
function changeValue(){
document.getElementsByClassName("form-control")[0].value = document.getElementsByClassName("text")[0].value;
}
</script>
<hr>
<div class="contacts_modal_search">
<input class="form-control contacts_modal_search_field no_outline ng-pristine ng-valid ng-empty ng-touched" my-focused="" type="search" placeholder="Search" ng-model="search.query" autocomplete="off" style="">
<a class="im_dialogs_search_clear tg_search_clear ng-hide" ng-click="search.query = ''" ng-show="search.query.length" style="">
<i class="icon icon-search-clear"></i>
</a>
</div>
Изменить значение поля ввода окна при загрузке окна (с помощью window.onload
):
<script>
window.onload = function(){
document.getElementsByClassName("form-control")[0].value = "your value";
}
</script>
<div class="contacts_modal_search">
<input class="form-control contacts_modal_search_field no_outline ng-pristine ng-valid ng-empty ng-touched" my-focused="" type="search" placeholder="" ng-model="search.query" autocomplete="off" style="">
<a class="im_dialogs_search_clear tg_search_clear ng-hide" ng-click="search.query = ''" ng-show="search.query.length" style="">
<i class="icon icon-search-clear"></i>
</a>
</div>