ドロップダウン メニューからオプションを選択するフォームを作成しました。オプションが選択されると、テキストフィールドに値が設定されます。私がやりたいことは、値の後のテキストフィールドに焦点を当てることです。例: ドロップダウンから facebook を選択すると、" http://www.facebook.com/ " がテキストフィールドの値として表示されます。facebook が選択されている場合、フォーカスは、既に追加されている値の最後の文字の後のテキスト フィールドにも移動します。
私はこれまでに持っているもので JSFiddle を作成しました:
JS:
$(document).ready(function() {
//Add the right URL prefix for social media
$('select').change(function() {
console.log(this.value);
if(this.value == "Facebook"){
$('#social-url').val("http://www.facebook.com/");
}
if(this.value == "Twitter"){
$('#social-url').val("http://www.twitter.com/");
}
if(this.value == "LinkedIn"){
$('#social-url').val("http://www.linkedin.com/");
}
});
});