Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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 如何卸下<;span>;标记为';在执行document.execCommand(';InsertUnderedList';)时是否应用?_Javascript_Html_Execcommand - Fatal编程技术网

Javascript 如何卸下<;span>;标记为';在执行document.execCommand(';InsertUnderedList';)时是否应用?

Javascript 如何卸下<;span>;标记为';在执行document.execCommand(';InsertUnderedList';)时是否应用?,javascript,html,execcommand,Javascript,Html,Execcommand,我有一个onlick函数,可以切换document.execCommand('insertunderedlist')当单击按钮将无序列表切换到其原始状态时,它会对HTML应用一个span标记,除非我删除所有文本和退格,否则该标记不会消失。这是一个问题,因为如果我不手动清除文本,并应用H1,跨度的内置字体大小将覆盖我的CSS,并应用比我当前在CSS中设置的H1小得多的字体大小 我试图将span设置为CSS中所需的fontsize,但因为它是通过execCommand动态呈现的,所以它不会读取我的C

我有一个onlick函数,可以切换document.execCommand('insertunderedlist')当单击按钮将无序列表切换到其原始状态时,它会对HTML应用一个span标记,除非我删除所有文本和退格,否则该标记不会消失。这是一个问题,因为如果我不手动清除文本,并应用H1,跨度的内置字体大小将覆盖我的CSS,并应用比我当前在CSS中设置的H1小得多的字体大小

我试图将span设置为CSS中所需的fontsize,但因为它是通过execCommand动态呈现的,所以它不会读取我的CSS。我尝试在切换完成后用document.execCommand('div',format,false)清除格式设置。我使用一个真-假布尔值在样式更改之间切换。它唯一有效的例子是,当我输入一些文本时,将UL列表从true切换到false,然后从那里切换到H1,这很好。但我担心的是,当用户按下UL按钮两次,然后尝试转到H1并获得小粗体字体,而不是全尺寸H1

let h1Size = true;
let h3Size = true;
let ulBullets = true;
function callResizeH1(){
document.getElementById('h1').addEventListener("click",function () {
    if(h1Size == true && ulBullets== true){
    h1Size = false;
    h3Size = true;
    ulBullets = true;

    document.execCommand( 'formatBlock',false,'<h1>')
   } else if(h1Size === true && ulBullets === false) {
    h1Size = false;
    h3Size = true;
    ulBullets = true;

document.execCommand('insertUnorderedlist', false, 'div')
document.execCommand( 'formatBlock',false,'<h1>')

}
else {
    h1Size = true;
    h3Size = true;
    ulBullets = true;

document.execCommand('formatBlock', false, 'div')
}
})
}
callResizeH1();

function noH1ResizeForUl() {
document.getElementById("bullet-list").addEventListener("click", 
function (){

    if (ulBullets || h3Size == false || ulBullets === true && h1Size 
 == false) {
        ulBullets = false;
        h1Size = true;
        h3Size = true;
        document.execCommand('formatBlock', false, 'div')
        document.execCommand('insertUnorderedlist', false, 'div')
        document.execCommand('formatBlock', false, 'div')
    }
    else{
        ulBullets = true;
        h1Size = true;
        h3Size = true;
        document.execCommand('formatBlock', false, 'div')
        document.execCommand('insertUnorderedlist', false, 'div')
        document.execCommand('formatBlock', false, 'div')
        return;
    }

})
}
noH1ResizeForUl()
让h1Size=true;
设h3Size=true;
让我们相信这是真的;
函数callResizeH1(){
document.getElementById('h1')。addEventListener(“单击”,函数)(){
如果(h1Size==true&&ulBullets==true){
h1Size=false;
h3Size=true;
ulBullets=true;
document.execCommand('formatBlock',false',)
}else if(h1Size==true&&ulBullets==false){
h1Size=false;
h3Size=true;
ulBullets=true;
document.execCommand('insertunderedList',false',div')
document.execCommand('formatBlock',false',)
}
否则{
h1Size=true;
h3Size=true;
ulBullets=true;
document.execCommand('formatBlock',false,'div')
}
})
}
callResizeH1();
函数noH1ResizeForUl(){
document.getElementById(“项目符号列表”).addEventListener(“单击“,
函数(){
如果(ul子弹头| | h3Size==false | | ul子弹头===true&&h1Size
==假){
ulbollets=假;
h1Size=true;
h3Size=true;
document.execCommand('formatBlock',false,'div')
document.execCommand('insertunderedList',false',div')
document.execCommand('formatBlock',false,'div')
}
否则{
ulBullets=true;
h1Size=true;
h3Size=true;
document.execCommand('formatBlock',false,'div')
document.execCommand('insertunderedList',false',div')
document.execCommand('formatBlock',false,'div')
返回;
}
})
}
noH1ResizeForUl()
我希望当ulBillets、h1Size和h3Size设置为true时,当我再次按下h1时,我会得到我想要的大小的h1。相反,span标记保留并设置为12pt,而不是CSS中定义的18pt