dongyou1926 2016-06-02 22:10
浏览 38
已采纳

使用Javascript,我可以“读取”页面上的h2类并检索和显示与该值相关的数据[关闭]

*not looking for code to be provided, just want to know if its possible.

For example. I have an h2 class named "stock-number" and its value is #NC123456. Can javascript read each instance of that class, fetch data from another database using that value, and display the results in another class.

Real world example would be if I sold TVs. The TV has an msrp and inventory is retrieved from one database. However, we can set a sale price. and the discounts and rebates are from another database, sorted by that tvs stock number.

Can I read that stock number, pull the pricing break down from the other database, and display in back into the page underneath the sale price in its own div so customers understand their savings?

  • 写回答

1条回答 默认 最新

  • douzhenggui8171 2016-06-02 22:17
    关注

    Yes, it can.

    In order to do the database lookup, receive the returned data, and update the DOM with new data, you also need to use AJAX.

    Basic ajax tutorial

    You might also want to compare jQuery code to the above pure javascript code -- most folks find jQuery a lot faster/easier (especially with AJAX).

    jQuery is a library that runs on top of javascript and all that is required in order to use it is to include the library somewhere on the page:

    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    </head>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法