Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.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 我希望在脚本中添加进一步的操作来更改类的css_Javascript - Fatal编程技术网

Javascript 我希望在脚本中添加进一步的操作来更改类的css

Javascript 我希望在脚本中添加进一步的操作来更改类的css,javascript,Javascript,我希望在脚本中添加进一步的操作来更改类的css document.write'DIV STYLE='display;无;;/>'}这是我最初的想法,但它似乎不工作,所以使用 if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) { document.write( '<base target="_blank" />' );

我希望在脚本中添加进一步的操作来更改类的css

document.write'DIV STYLE='display;无;;/>'}这是我最初的想法,但它似乎不工作,所以使用

    if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) {
document.write( '<base target="_blank" />' );
     }
再加上

    if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) {
document.write( '<base target="_blank" />' ); document.write( 'DIV STYLE='display;none;); />' ) 
    }
尸体是

     <div class="headerlogo"> Serious Photography </div>
     <div> Serious Photography 2 </div>

这是一个很难理解的问题,但是如果你想检查你在哪一页,你可以使用

window.location.href 
然后,匹配字符串的条件检查可以决定是否要添加新样式。我会把班级改成ID

那你就可以了

document.getElementById('headerlogo').style.display = 'none';
就我个人而言,我会使用SIZZLE或jQuery来简化选择器

$('.headerlogo').css('display', 'none');
请避免使用document.write。这里有一个解释原因的例子。 indexOf的参数也包含无效语法。HTML基础也与应用样式和'DIV STYLE='display'无关;无;;/>是不正确的HTML/CSS语法,并且在将样式应用于headerlogo类时也没有任何效果

这对于向可能还不存在的类和ID添加样式标记非常有用

if (location.href.indexOf(
       "/smispage/tpfpage/client_images_new/client_images_list") > -1
) {
    var style = document.createElement('style');
    style.type = 'text/css';
    style.appendChild(document.createTextNode('.headerlogo{display:none;}'));
    document.getElementsByTagName('head')[0].appendChild(style);
}

因此,您想添加一个样式来制作.headerlogo显示:无?仅当在位置上时,如果location.href.indexOf/smispage/tpfpage/client\u images\u new/client\u images\u list@MatthewKelly为什么不使用不同的html页面?它用于修改第三方商店图像销售解决方案页面-在某些情况下,我希望链接在新窗口中打开-通过默认情况下,它们在同一个窗口中打开-它们以前在新窗口中打开-我的收藏页面是一个200px高的信箱,因此if location.href.indexOf/smispage/tpfpage/client\u images\u new/client\u images\u list>-1{document.write;我希望标题在除信箱外的所有情况下都出现,因此我希望通过display:none添加hide.headerlogo;在上述链接中的所有场景中,最后我使用if location.href.search/\/smis | tpfpage | client|u images | new list/>-1{document.write;var style=document.createElement'style';style.type='text/css';style.appendChilddocument.createTextNode.headerlogo{display:none;}';document.getElementsByTagName'head'[0]。appendChildstyle;}这就是为什么我添加了警告,在这个例子中我会改为ID或者使用SIZZLE。忘记在我的原始帖子中添加它了。你可以使用getElementsByClassName,但只有在你不支持lt IE8ok的情况下。我如何将它添加到if location.href.indexOf/smispage/tpfpage/client\u images\u new/client\u images\u list>-1{document.write;似乎不起作用}执行if location.href.indexOf/smispage/tpfpage/client_images\u new/client_images\u list>-1{document.write;document.getElementById'headerlogo'.style.display='none';}感谢对if location.href.search/\/smis\tpfpage | client_images\u new | list/>-1的帮助{document.write;var style=document.createElement'style';style.type='text/css';style.appendChilddocument.createTextNode.headerlogo{display:none;}';document.getElementsByTagName'head'[0]。appendChildstyle;}相反,我会使用jquery,但我能做的有限,比如修改允许非链接嵌入的第三方网站:if location.href.search/\/smis | tpfpage | client|u images | new | list/>-1{document.write;var style=document.createElement'style';style.type='text/css';style.appendChilddocument.createTextNode.headerlogo{display:none;}';document.getElementsByTagName'head'[0]。appendChildstyle;}似乎可以正常工作,非常感谢