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 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办