doujiku1028 2017-05-01 09:54
浏览 62
已采纳

如何使用Javascript以外的语言操作DOM? [关闭]

So I have been wondering how can I manipulate DOM in languages other than Javascript and PHP. I can always use Javascript and PHP in one HTML file with other HTML and CSS code.

Similarly, in Javascript there are multiple methods such as document.getElemenyById() etc. In PHP, basically it is a hypertext pre-processor and thus it automatically renders HTML through the server which again can be used for DOM Manipulation.

What about other languages? Can we use them to build the web? Or specifically, do things like HTML and CSS Manipulation. Let's say for example, Python or C#. How can I use them like JS and PHP?

  • 写回答

2条回答 默认 最新

  • douse8732 2017-05-01 10:24
    关注

    There are two stages of "working" with DOM. The first stage is the server render. When PHP engine receives template (mix of HTML, PHP) plus data and outputs valid HTML to a browser. In this stage, you can build HTML that will be parsed by a browser to DOM tree. You don't work with DOM, but rather with a plain text of your template.

    The second stage is the Javascript evaluation. A browser parses and runs JS, and this JS has access to DOM tree.

    The first stage can be done in any language that runs on a server. You can use c# templates, python templates, go templates, even javascript. All template engines just proceed template (text) and data and give text output which can be valid HTML.

    The second stage works only with JS because browsers work with JS only. There were some attempts to bring other languages to a frontend (like Dart), and all failed. But you have some options. There are many compilers for existing languages that can target JS. For example, clojruescript for clojure, bucklescript for ocaml, gopherjs for go and others. Also, there are bunch of languages which created for this purpose (compile to JS): purescript, elm, typescript, etc. Modern browsers can use webassembly binary packages. It differs from JS, but also don't have access to DOM.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误