Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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
使用jQuery从SELECT中的选项中获取两个单独的值_Jquery_Forms_Select_Input - Fatal编程技术网

使用jQuery从SELECT中的选项中获取两个单独的值

使用jQuery从SELECT中的选项中获取两个单独的值,jquery,forms,select,input,Jquery,Forms,Select,Input,我正在尝试从选择输入中的一个选项中获取两个值 以下是我得到的: jQuery: $(document).ready(function() { $( "#embed-layout-options" ).change(function () { var widthval = $(this).attr('data-width'); var heightval = $(this).attr('data-height'); var

我正在尝试从选择输入中的一个选项中获取两个值

以下是我得到的:

jQuery:

$(document).ready(function() { 
$( "#embed-layout-options" ).change(function () {
            var widthval = $(this).attr('data-width');
            var heightval = $(this).attr('data-height');
            var urlcode = "<iframe src='http://videos.enteratenorte.com/embed/"+widthval+"-"+heightval+"/6NExpBjXme' width='"+widthval+"' height='"+heightval+"' frameborder=0 webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
            $("#codeemb").val(urlcode);
})
});
HTML:

它确实发生了变化,但不是一个数字,而是一个未定义的数字

您可以在此处进行测试:


谢谢

您必须找到所选选项,如:

$document.readyfunction{ $embed-layout-options.changefunction{ var-widthval=$:已选定,此.attr'data-width';//此处获取选定选项 var heightval=$:selected,this.attr'data-height';//here get selected选项 var urlcode=; $codeemb.valurlcode; } }; 尺寸: 560 × 315 640 × 360 720 × 405 853 × 480 1280 × 720 属性位于选项上,而不是选择,更改处理程序中的属性是选择。 您可以使用.find获取所选选项

var widthval = $(this).find(":selected").attr('data-width'); 
var heightval = $(this).find(":selected").attr('data-height'); 
var widthval = $(this).find(":selected").attr('data-width'); 
var heightval = $(this).find(":selected").attr('data-height');