如何改变HTML的部分使用Javascript,当一个链接被点击? [英] How to change parts of HTML with Javascript when a link is clicked on?

查看:135
本文介绍了如何改变HTML的部分使用Javascript,当一个链接被点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个名为录像机DIV - 这里面DIV是一个图像。

Let's say I have a DIV named "videoplayer" -- inside this DIV is an image.

有一个简单的方法来改变HTML code这个DIV里面,当一个链接被点击?

Is there a simple way to change the HTML code inside this DIV when a link is clicked on?

例如,这是当前DIV:

For example, this is the current DIV:

    <div class = "big_player" id="player1">
             <img src="whatever.jpg">
    </div>

当点击一个链接,我想在HTML更改为:

When a link is clicked, I want the HTML to change to:

    <div class = "big_player" id="player1">
             <script>
                playVideo(file, stream, key);
             </script>
    </div>

什么是实现这一目标的最简单,最简单的方法是什么?

What is the simplest and easiest way to accomplish this?

推荐答案

修改

试试这个:

$("img").on("click", function(e){

var content = "<script>" +
                   "playVideo(file, stream, key);" +
              "</script>";

$(this).parent().html(content);

});

只要确保在的playVideo()及其所有参数的存在。给我一个反馈,如果它没有工作。我们可以使用的的eval()的,如果它失败了。

just make sure the playVideo() and all its parameters is existing. Send me a feedback if it didnt work. We might use eval() if it failed.

这篇关于如何改变HTML的部分使用Javascript,当一个链接被点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆