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 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型
  • ¥15 Python 如何安装 distutils模块
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?