我在视图中有这段代码
<a href="#SampleEditor" onclick="javaScript:ShowSampleEditor()"
id="SampleLink">Add Sample</a>
<div class="editor-field" id="SampleEditor" style="display: none">
<div class="editor-label">
@Html.LabelFor(model => model.SampleCollectionInstructions)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.SampleCollectionInstructions, new { @class = "adminRichText" })
@Html.ValidationMessageFor(model => model.SampleCollectionInstructions)
</div>
</div>
它的作用是向用户显示一个链接以打开富文本编辑器并隐藏链接
这是我使用的代码
function ShowSampleEditor() {
$("#SampleEditor").show();
$("#SampleLink").hide();
}
现在我必须为更多的编辑做这件事。由于Json不是我的事,我如何为sevearal编辑器制作一个通用函数呢?
答案 0 :(得分:0)
将代码编辑为以下内容
<a href="#SampleEditor" onclick="javaScript:ShowSampleEditor(this)"
id="SampleLink">Add Sample</a>
<div class="editor-field" id="SampleEditor" style="display: none">
<div class="editor-label">
@Html.LabelFor(model => model.SampleCollectionInstructions)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.SampleCollectionInstructions, new { @class = "adminRichText" })
@Html.ValidationMessageFor(model => model.SampleCollectionInstructions)
</div>
</div>
和javascript到
function ShowSampleEditor(link) {
$(link).next().show(); // Next element after the link is the panel
//$(".editor-field").show(); // Use this if the element to show does not immediately follow the link
$(link).hide();
}
看一个演示小提琴
我已经将javascript函数概括为将点击的链接作为参数。这个链接是隐藏的,它是下一个兄弟节目 - 应该是编辑。