Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 不';不要把宽度加在跨度上 HTML 5 4 JQuery jQuery(文档).ready(函数(){ jQuery('.stars1')。每个(函数(){ var star=jQuery(this); html(“+star.prev('.review rating').text()+”); }); jQuery('.stars').stars(); }); jQuery.fn.stars=函数(){ 返回jQuery(this).each(function(){ jQuery(this).html(jQuery(“”.width)(Math.max(0,(Math.min(5,parseFloat($(this.html()))))))*16)); }); }_Javascript_Jquery_Html - Fatal编程技术网

Javascript 不';不要把宽度加在跨度上 HTML 5 4 JQuery jQuery(文档).ready(函数(){ jQuery('.stars1')。每个(函数(){ var star=jQuery(this); html(“+star.prev('.review rating').text()+”); }); jQuery('.stars').stars(); }); jQuery.fn.stars=函数(){ 返回jQuery(this).each(function(){ jQuery(this).html(jQuery(“”.width)(Math.max(0,(Math.min(5,parseFloat($(this.html()))))))*16)); }); }

Javascript 不';不要把宽度加在跨度上 HTML 5 4 JQuery jQuery(文档).ready(函数(){ jQuery('.stars1')。每个(函数(){ var star=jQuery(this); html(“+star.prev('.review rating').text()+”); }); jQuery('.stars').stars(); }); jQuery.fn.stars=函数(){ 返回jQuery(this).each(function(){ jQuery(this).html(jQuery(“”.width)(Math.max(0,(Math.min(5,parseFloat($(this.html()))))))*16)); }); },javascript,jquery,html,Javascript,Jquery,Html,在所有的现金交易中表现不同 在html页面头标记中添加JQuery时工作正常,但当我尝试在Joomla中添加自定义html时根本不起作用 当我试着在“jsfiddle”时,给了我跨度,但没有宽度 如何将跨度与宽度相加 Jquery应该返回如下内容 <script type='text/javascript'> jQuery(document).ready(function () { jQuery('.stars1').each(func

在所有的现金交易中表现不同

在html页面头标记中添加JQuery时工作正常,但当我尝试在Joomla中添加自定义html时根本不起作用

当我试着在“jsfiddle”时,给了我跨度,但没有宽度


如何将跨度与宽度相加

Jquery应该返回如下内容

<script type='text/javascript'>    
        jQuery(document).ready(function () {
            jQuery('.stars1').each(function () {
                var star = jQuery(this);
                star.html("<span class='stars'>" + star.prev('.review-rating').text() + "</span>");
            });
            jQuery('.stars').stars();
        });

        jQuery.fn.stars = function() {
            return jQuery(this).each(function() {
                jQuery(this).html(jQuery("<span />").width(Math.max(0, (Math.min(5, parseFloat($(this).html())))) * 16));
            });
        }
</script>
“”

跨距是内联元素,内联元素没有固定的宽度

因此,您的范围需要将显示设置为块或内联块

 "<span class="stars"><span style="width: 75.2px;"></span></span>"
另一个问题是跨度内没有文本,因此没有显示任何内容


jQuery(文档).ready(函数(){
jQuery('.stars1')。每个(函数(){
var star=jQuery(this);
html(“+star.prev('.review rating').text()+”);
});
jQuery('.stars').stars();
});
jQuery.fn.stars=函数(){
返回jQuery(this).each(function(){
jQuery(this).html(jQuery(“”.width)(Math.max(0,(Math.min(5,parseFloat($(this.html())))))*16.html(“”);
});
}
span.span{
背景色:红色;
显示:内联块;
}

5
4

您的问题是什么?如何添加带宽度的跨距。?跨距没有要设置的宽度。仍然适用,跨距没有宽度,选择器只需要更改。感谢您的解释,我正在做与您在此处所做的相同的事情,但在此处不起作用,因为您正在运行代码,并且您定义了stars()在你使用它的地方之后。若你们把它移到前面,或者把小提琴换成在身体里演奏,它就会起作用。
 "<span class="stars"><span style="width: 75.2px;"></span></span>"
span.stars span { display: inline-block; }