Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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_Css - Fatal编程技术网

Javascript 指定';标题';属性到样式表不';你不允许它被应用吗?

Javascript 指定';标题';属性到样式表不';你不允许它被应用吗?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有这样的代码: $(document).ready(function () { var style = $('#formulario').val(); $('#formulario').change(function() { var nombreArchivo = $(this).val(); nombreArchivo = nombreArchivo.replace(/ /gi, '_'); var ruta = '/printbox/views/form

我有这样的代码:

$(document).ready(function () {

  var style = $('#formulario').val();

  $('#formulario').change(function() {
    var nombreArchivo = $(this).val();
    nombreArchivo = nombreArchivo.replace(/ /gi, '_');
    var ruta = '/printbox/views/formulariosweb/';
    $('#contenedorFormulario').load( ruta + nombreArchivo + '.html');
    $('head').append( $('<link rel="stylesheet" type="text/css"/>').attr('href', ruta + nombreArchivo + '.css') );
  });

  $("#formulario").trigger('change');

});
任何帮助都将不胜感激

谢谢


PS:我添加title属性是为了在以后更改下拉列表中的值时能够识别和删除它,这样它就不会填充标题。

您可以使用以下命令检查样式表是否尚未加载:

if (!$("link[href='/path/to.css']").length)
因此,如果最终目标是只希望加载每个样式表一次,那么您的代码将是:

$(document).ready(function () {

  var style = $('#formulario').val();

  $('#formulario').change(function() {
    var nombreArchivo = $(this).val();
    nombreArchivo = nombreArchivo.replace(/ /gi, '_');
    var ruta = '/printbox/views/formulariosweb/';
    $('#contenedorFormulario').load( ruta + nombreArchivo + '.html');
    if (!$("link[href='" + ruta + nombreArchivo + "'.css']").length) {
      $('head').append( $('<link rel="stylesheet" type="text/css"/>').attr('href', ruta + nombreArchivo + '.css') );
    }
 });

 $("#formulario").trigger('change');

});
$(文档).ready(函数(){
var style=$('#formulario').val();
$('#formulario')。更改(函数(){
var nombreArchivo=$(this.val();
nombreArchivo=nombreArchivo.replace(//gi,'.''');
var ruta='/printbox/views/formulariosweb/';
$('contendorformulario').load(ruta+nombreArchivo+'.html');
if(!$([link[href='“+ruta+nombreArchivo+”.css'])长度){
$('head').append($(''.attr('href',ruta+nombreArchivo+'.css'));
}
});
$(“#formulario”).trigger('change');
});

我向Mozilla bugtrack报告了这个问题,发现了一个类似的问题(),在这里讨论了这个问题,并将我带到了这个页面:

其中规范说明指定
title
属性使其成为首选样式,然后不应用其他样式

Authors may specify a number of mutually exclusive style sheets called alternate style sheets. Users may select their favorite among these depending on their preferences.
For instance, an author may specify one style sheet designed for small screens and another for users with weak vision (e.g., large fonts).
User agents should allow users to select from alternate style sheets.

The author may specify that one of the alternates is a preferred style sheet. User agents should apply the author's preferred style sheet unless the user has selected a different alternate.

您在哪里看到
链接
支持
标题
?我在学校里什么也没看到。还有,你为什么要使用它?@vcampitelli Global Attributes标签也支持HTML中的全局属性。感谢你的回答Blake,我发现它可能是一个带有
title
属性的bug,因为我将它改为使用
id
,并按预期工作,我已经有办法使用jquery的
remove
一次只加载一个。
Authors may specify a number of mutually exclusive style sheets called alternate style sheets. Users may select their favorite among these depending on their preferences.
For instance, an author may specify one style sheet designed for small screens and another for users with weak vision (e.g., large fonts).
User agents should allow users to select from alternate style sheets.

The author may specify that one of the alternates is a preferred style sheet. User agents should apply the author's preferred style sheet unless the user has selected a different alternate.