Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.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 使用DOM属性创建的样式按钮?_Javascript_Html_Css - Fatal编程技术网

Javascript 使用DOM属性创建的样式按钮?

Javascript 使用DOM属性创建的样式按钮?,javascript,html,css,Javascript,Html,Css,在这里,我在列表标签中动态添加按钮。按钮出现在列表附近,我正在尝试将其向右移动。当dom创建按钮时,有什么方法可以做到这一点吗。我们需要这方面的指导 { var button = document.createElement("button"); button.innerHTML = "Add To Favourite"; button.setAttribute('onclick', 'addFavourite("' + movie['title'] +

在这里,我在列表标签中动态添加按钮。按钮出现在列表附近,我正在尝试将其向右移动。当dom创建按钮时,有什么方法可以做到这一点吗。我们需要这方面的指导

{
    var button = document.createElement("button");
    button.innerHTML = "Add To Favourite";
    button.setAttribute('onclick',
        'addFavourite("' + movie['title'] + '")');
    data.appendChild(button);
}

您可以使用
float:right
将按钮移动到
  • 的最右侧。您也可以使用
    左边距:40px
    将其移动到
  • var data=document.getElementById('container');
    var button=document.createElement(“按钮”);
    button.innerHTML=“添加到收藏夹”;
    button.className='liBtn';
    button.setAttribute('onclick',
    "addfavorite("sss));;
    data.appendChild(按钮)
    
    .liBtn{
    左边距:40px;
    }
    • 列表1

    您可以使用
    float:right
    将按钮移动到
  • 的最右侧。您也可以使用
    左边距:40px
    将其移动到
  • var data=document.getElementById('container');
    var button=document.createElement(“按钮”);
    button.innerHTML=“添加到收藏夹”;
    button.className='liBtn';
    button.setAttribute('onclick',
    "addfavorite("sss));;
    data.appendChild(按钮)
    
    .liBtn{
    左边距:40px;
    }
    • 列表1

    如果要调整,请尝试调整左边距。检查一下我为你的案子写的这封信。希望它能起作用

    如果要调整,请尝试
    左边距
    。检查一下我为你的案子写的这封信。希望它能起作用

    您可以直接使用内联属性
    浮点或边距(button.style.float=“right”)

    或者您可以使用
    el.style
    设置内联样式,并在此字符串中传递所有样式。大概是这样的:

    // Create element
    var button = document.createElement("button");
    button.innerHTML = "Add To Favourite";                     
    button.setAttribute('onclick', addFavourite("'+movie['title']+'"));
    
    // Styling
    var styleButton = "float: right; margin-left: 10px;";
    button.setAttribute('style', styleButton);
    
    // append
    data.appendChild(button);
    
    使用浮点:


    使用边距:

    您可以直接使用内联属性
    浮点或边距(button.style.float=“right”)

    或者您可以使用
    el.style
    设置内联样式,并在此字符串中传递所有样式。大概是这样的:

    // Create element
    var button = document.createElement("button");
    button.innerHTML = "Add To Favourite";                     
    button.setAttribute('onclick', addFavourite("'+movie['title']+'"));
    
    // Styling
    var styleButton = "float: right; margin-left: 10px;";
    button.setAttribute('style', styleButton);
    
    // append
    data.appendChild(button);
    
    使用浮点:


    使用边距:

    Does
    button.style.float=“right”帮助你?给你
    button.style.float=“right”帮你?你看,它移动得太右了,我们怎么能留出一些空间或调整宽度?@Shiva use
    左边距:40px然后。检查更新后的答案它没有显示效果,但我添加了css文件的正确路径@ankitts移动得太右了,我们如何才能留出一些空间或调整宽度?@Shiva use
    左边距:40px然后。检查更新的回答它没有显示效果,但我添加了css文件的正确路径@ankitelt未在此处定义或使用?抱歉@Shiva它是
    按钮而不是
    elt
    =这里没有定义或使用Delt?抱歉@Shiva它是
    按钮而不是
    elt
    =D