首先,我搜索了该站点并发现了以下内容:
但它不适合我的需要,因为我正在生成很长的模板,并且上述方法太耗时且不切实际,因为这意味着用我的模板填充每个标签的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 日星期五下午 1:17:34
为了澄清上面我所说的“当我测试这个时我什至没有收到脚本错误,它根本不起作用,”
我的意思是,如果我将模板全部放在一行上,即
/*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. ",
然后我得到一个“未终止的字符串常量”错误。使用会\n
解决这个错误吗?另外,我把它排除在脚本之外是因为我不知道该怎么做,但是在<textarea>
它说的地方
Templates will auto-populate
here depending on the
selection made from the
[CSTemplates]
drop-down list.
当用户从下拉列表中选择一个选择时,我需要删除,并<textarea>
使用脚本中的相应选择来填充。谢谢!