Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从javascript发送到servlet:获取按钮旁边的嵌套元素的数据_Javascript_Java_Servlets - Fatal编程技术网

将数据从javascript发送到servlet:获取按钮旁边的嵌套元素的数据

将数据从javascript发送到servlet:获取按钮旁边的嵌套元素的数据,javascript,java,servlets,Javascript,Java,Servlets,我有一个带有视频div和按钮的简单html: <div class = "video-row"> <iframe width="560" height="315" src="https://www.youtube.com/embed/QmHCn5xXHjI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullsc

我有一个带有视频div和按钮的简单html:

<div class = "video-row">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/QmHCn5xXHjI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    <div class="add-button green-button light-button">Add video</div>


</div>

如何获取视频的url,即
src
标记的值?页面上会有许多这样的视频,每个视频都有一个添加按钮。

找到单击的元素父元素,然后找到
iframe
子元素:

$(文档)。在(“单击”,“添加”按钮)上,函数(事件){
var button=$(event.target);//查找单击的按钮
//查找视频元素,首先查找父元素
var videoElement=button.parents(“.video行”).find(“iframe”);
console.log(videoElement.attr(“src”);//获取“src”属性
});

添加视频
$(document).on("click", ".add-button", function () {  
           sendData();
});
var sendData = function()  {
    $.ajax({
        url: "addcomedian",
        type: "post", //send it through get method
        data: {
            number: 4,
            sender: "add-button",
            url: url,
        },
     success:
        ...
}