Is it possible to put read-only text inside input alongside writable text?
I want to make an input with some read-only text and some writable text. It should always say "www." at the beginning (read only) and afterwards the user should be able to write wh开发者_开发问答atever he wants. What is the easiest way to do this?
The "easiest" way would be to have a separate element underneath (or surrounding) the input
.
http://jsfiddle.net/NxWBT/
However, this'll be for presentational purposes only. If you need the www
part submitted, you'll have to add it with Javascript before the form is submitted.
On KeyDown event you can get the string an append it
function onblurwww(){
var tb = document.getElementById('myTextBox');
var val = tb.value;
if (val.substr(0, 4) != 'www.')
tb.value = 'www.' + val;
}
something like that in your keydown on the textbox.
精彩评论