Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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 如何从另一个属性替换属性值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何从另一个属性替换属性值

Javascript 如何从另一个属性替换属性值,javascript,jquery,html,Javascript,Jquery,Html,我需要知道,如何用jQuery替换另一个attr(rel)中的样式宽度值,例如: 示例: 我需要这个: 使用jquery.$('mySpan').css('width',$('mySpan').attr('rel')+“%”)应该可以工作。 但对于此解决方案,您必须将id=“mySpan”添加到span标记。试试这个。我正在使用id选择器获取您想要的跨度 var this_span = $('#theSpan') this_span.css('width',this_span.attr('rel

我需要知道,如何用jQuery替换另一个attr(rel)中的样式宽度值,例如:

示例:

我需要这个:

使用jquery.

$('mySpan').css('width',$('mySpan').attr('rel')+“%”)应该可以工作。

但对于此解决方案,您必须将
id=“mySpan”
添加到span标记。

试试这个。我正在使用id选择器获取您想要的跨度

var this_span = $('#theSpan')
this_span.css('width',this_span.attr('rel')+'%')
您可以这样做:

$('span[rel]').each(function() {
    var span = $(this);
    span.css('width', span.attr('rel') + '%');
});

这将获得所有具有
rel
属性的

非常感谢,工作很好,现在我如何添加动画和设置时间?是否要使用动画更改其先前的宽度?
$('#mySpan').animate({width:$('#mySpan').attr('rel')+“%”,2000)应该可以,2000年是需要时间的汉克斯,非常感谢