简体   繁体   English

如何使用html工作的javascript也可以在cshtml中工作?

[英]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() }) 
//]]>

jsfiddle example jsfiddle的例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使我的 HTML 命令框与 JavaScript 一起使用? - How can I make my HTML command box work with JavaScript? 如何在asp.net cshtml文件中获取我的JavaScript代码? - How can I get my javascript work in an asp.net cshtml file? 如何在Durandal中使用.cshtml和.html文件 - How can I use .cshtml and .html files with Durandal 如何使 javascript function 适用于 html 和 ZC7A628CBA22E28EB17AAZZ6C65 中的许多可扩展卡 - How can I make a javascript function work for many expandable cards in html and css 如何制作一个也适用于移动设备的水平滚动导航栏 - How can I make a Horizontal scrolling nav bar that also works with mobile 如何使用javascript使三个html音频元素按顺序重复工作 - How can i make three html audio elements work sequentially repeated using javascript 为什么这个 html javascript 文件不起作用,我怎样才能让用户输入不是正数? - why this html javascript file doesnt work and how can i make user input to not be anything but positive number? 代码在CSHTML中有效,但在外部Javascript文件中无效 - Code works in CSHTML but does not work in external Javascript file 当用户在新窗口中打开时,如何使onclick“ window.location”也起作用 - javascript - How do I make onclick“window.location” also work when user opens in new window 如何使功能与等待同时还可以进行回调? - How to make function that works with await but also can take callback?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM