1

Ребят подскажите пожалуйста как передать url изображения в поле input text при клике на изображение

1

2 ответа 2

2
<input type="text" id="inputId" />
<img onclick="document.getElementById('inputId').value=this.src" id="imgId" src="...

$("#imgId").click(function() { $("#inputId").val(this.src); });
1

Можете использовать событие click на картинке. Чтобы получить значение атрибутов, можете метод jquery attr или prop

$("#my_image").on('click', function(e) {
  $("#my_input").val(e.target.src)
  console.log(e.target.src)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<img id="my_image" src="https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg" alt="click and move url to input" width=200 height=200/>
<input id="my_input" type="text"/>
</div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.