[英]How can I make a javascript that works in html also work in cshtml?
I have this html page I copied from here . 我有这个从这里复制的html页面。 There is a javascript used that changes text areas into rich text editors.
有一个javascript用于将文本区域更改为富文本编辑器。 It works like it should when I just copy it in a file and open it with a browser.
当我将它复制到文件中并用浏览器打开时,它的工作方式就像它应该的那样。 However, when I try to put it in my c# project and put it in a cshtml file (without changing anything) it ignores(?) the javascript and shows the textareas as plain textareas.
但是,当我尝试将它放入我的c#项目并将其放入cshtml文件(不更改任何内容)时,它会忽略(?)javascript并将textareas显示为纯textareas。 How can I make this work in cshtml?
如何在cshtml中完成这项工作?
The code, same in html page as cshtml page: 代码,在html页面中与cshtml页面相同:
<div id="sample">
<script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
<script type="text/javascript">
//<![CDATA[
bkLib.onDomLoaded(function () { nicEditors.allTextAreas() });
//]]>
</script>
<h4>
First Textarea
</h4>
<textarea name="area1" cols="35">
</textarea><br />
<h4>
Second Textarea
</h4>
<textarea name="area2" style="width: 100%;">
Some Initial Content was in this textarea
</textarea><br />
<h4>
Third Textarea
</h4>
<textarea name="area3" style="width: 300px; height: 100px;">
HTML content default in textarea
</textarea>
</div>
When you copied and pasted the code into your cshtml, did you reference their copy of the nicEdit-latest.js file, or did you save a local copy of it. 当您将代码复制并粘贴到cshtml中时,是否引用了nicEdit-latest.js文件的副本,或者是否保存了本地副本。
As far as I can see it should work if you copied the HTML over exactly the way they have it. 据我所知,如果你完全按照它们的方式复制HTML,它应该可以工作。
try using the following if you are referencing a local copy of the js file 如果要引用js文件的本地副本,请尝试使用以下命令
<script src="@Url.Content("~/PATH_TO_YOUR_FILE/nicEdit-latest.js")" type="text/javascript"></script>
EDIT This should work. 编辑这应该工作。
Add a reference Jquery to if you haven't yet, and modify the code to look like this 如果还没有,请添加引用Jquery,并将代码修改为如下所示
//<![CDATA[
$(document).ready(function() {nicEditors.allTextAreas() })
//]]>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.