まず、サイトを検索したところ、次のことがわかりました。
しかし、私は非常に長いテンプレートを生成しており、上記の方法は、各タグのvalue
属性をテンプレートで埋めることを意味するため、時間がかかりすぎて実用的ではないため、私のニーズには合いませんでした.<option>
コードは次のとおりです。
<script type="text/javascript">
//<![CDATA[
function showCSTemplates(sel){
locations =[ "", /*this remains blank for first selection in drop-down list*/
/*option 1*/
" This is template 1 that will appear in a
textarea keeping
its formatting
as
is. ",
/*option 2*/
" This is template 2 that
will appear in a
textarea keeping its
formatting as is.
Credentials:
Contact Info: ",
/*option 3*/
" This is template 3 that will appear in a
textarea keeping its formatting as is.
Donec tortor lorem,
ornare vitae commodo nec,
sagittis et nunc.
Maecenas sagittis quam ",
/*option 4*/
"etc",
/*option 5*/
"etc...", ];
srcLocation = locations [sel.selectedIndex];
if (srcLocation != undefined && srcLocation != "") {
document.getElementById('CSTemplates').innerHTML = srcLocation;
}
} //]]>
</script>
マークアップは次のとおりです。
<h1>Note Generator</h1>
<div class="left">
CSTemplates
<p>
<select class="c10">
<option selected="selected" value="" id="Templates" onchange="showCSTemplates(this);">Please select a template...</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</p>
<p>
<textarea cols="30" rows="20" readonly="readonly" id="CSTemplates">
Templates will auto-populate
here depending on the
selection made from the
[CSTemplates]
drop-down list.
</textarea>
</p>
</div><!--left ends here-->
最悪の部分は、これをテストしてもスクリプト エラーが発生しないことです。まったく機能しないため、どこで問題が発生したのかわかりません。<input type="text">
タグを使用して同様のページを作成しましたが、うまく機能しましたが、<textarea>
何を試してもまったく機能しないようです。
どんな助けでも大歓迎です!前もって感謝します!
編集日: 2011 年 9 月 2 日 (金) 01:17:34 PM
上記の説明を明確にするために、「これをテストしてもスクリプト エラーは発生しません。まったく機能しません」と述べました。
つまり、テンプレートをすべて 1 行に残した場合、つまり
/*option 1*/
" This is template 1 that will appear in a textarea keeping its formatting as is. ",
その後、エラーは発生しません。ただし、上記のような書式設定のために改行を入力すると:
/*option 1*/
" This is template 1 that will appear in a
textarea keeping
its formatting
as
is. ",
その後、「Unterminated string constant」エラーが発生します。を使用して\n
このエラーを解決しますか? また、どうすればいいのかわからないため、スクリプトから除外しましたが<textarea>
、それが言う場所で
Templates will auto-populate
here depending on the
selection made from the
[CSTemplates]
drop-down list.
ユーザーがドロップダウンリストから選択したときに消去し<textarea>
、スクリプトから対応する選択を入力する必要があります。ありがとう!