admin管理员组文章数量:1415698
I am trying to include an img tag inside an input's value attribute. I would like something like this using jquery:
<input type="text" value="Lorem Impsum <img src='...'/>" />
I already tried this:
jQuery(document).ready(function() {
productinput = jQuery('input[value=product]');
productinput.val(data.selectedData.value + '<img style="width:128px" src="' + data.selectedData.imageSrc + '" />');
});
but it's not working. So, does anyone know how I can do this?
Note: it is an image inside the value.
I am trying to include an img tag inside an input's value attribute. I would like something like this using jquery:
<input type="text" value="Lorem Impsum <img src='...'/>" />
I already tried this:
jQuery(document).ready(function() {
productinput = jQuery('input[value=product]');
productinput.val(data.selectedData.value + '<img style="width:128px" src="' + data.selectedData.imageSrc + '" />');
});
but it's not working. So, does anyone know how I can do this?
Note: it is an image inside the value.
Share Improve this question edited Jan 27, 2016 at 14:58 wpercy 10.1k4 gold badges34 silver badges49 bronze badges asked Jan 27, 2016 at 11:00 KelyaneKelyane 4672 gold badges7 silver badges19 bronze badges 3- why do you need to use image like this? – Parth Trivedi Commented Jan 27, 2016 at 11:02
- I would say that's not valid HTML? – mnille Commented Jan 27, 2016 at 11:03
-
The
img
tag would not be parsed, it's a string in this context. So unless you want to send this input's value to server and save it somewhere, you can't do this – Adam Azad Commented Jan 27, 2016 at 11:05
3 Answers
Reset to default 1You can set the image by putting image as the background of the element
For example
html
<input type="text" value="Lorem Impsum" class="default" />
css
input.default{
background: url('../images/any.jpg') 0 0 no-repeat;
}
You can set the css of the element using jquery on document ready.
You should set the type to image.
<input type="image" name="image" src="image.png" width="50">
Try to read doc: Mozilla documentation input/image
Try using the attribute "contenteditable" on a div
<div contenteditable> Lorem ipsum.. <img src='..'> </div>
本文标签: javascriptSet image in an input valueStack Overflow
版权声明:本文标题:javascript - Set image in an input value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745238346a2649171.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论