Html 单击链接时如何更改内联css样式?

Html 单击链接时如何更改内联css样式?,html,css,styles,Html,Css,Styles,我用inlinestyle=“display:none;”隐藏了一个表单 当单击页面上的链接时,如何将此样式更改为style=“display:inline;”“?在锚点上绑定一个onclick事件,并将表单样式设置为display:block,这里有一个js小提琴帮助您 首先,您需要找到使用JavaScript选择表单的方法;这里有一个函数,假设您的表单具有id属性myform: function showForm() { document.getElementById('myform

我用inline
style=“display:none;”隐藏了一个表单


当单击页面上的链接时,如何将此样式更改为
style=“display:inline;”“

在锚点上绑定一个
onclick
事件,并将表单样式设置为
display:block
,这里有一个js小提琴帮助您


首先,您需要找到使用JavaScript选择表单的方法;这里有一个函数,假设您的表单具有
id
属性
myform

function showForm() {
    document.getElementById('myform').style.display = 'inline';
}
然后,只需将该函数绑定到链接的
单击事件。一种快速而肮脏的方法是将链接的
onclick
属性设置为
showForm();返回false,但您可能希望在外部JavaScript中这样做,以便很好地分离您的内容和行为。

请检查此JQuery

作秀

$("#lnk").click(function () {  
$("#result").removeAttr('Style');
$("#result").attr('Style','display: inline;'); // this 
$("#result").attr('Style','display: block;'); // or this

}); 
隐藏

$("#lnk").click(function () {  
$("#result").removeAttr('Style');
$("#result").attr('Style','display: none;');
}); 
相当简单

<a href="#" onclick="document.getElementById('myform').style.display = 'inline';">Click me</a>
现在让我们编写jquery

$(document).ready(function() {
// ^ This is an event, which triggers once all the document is loaded so that the manipulation is always guaranteed to run.
   $("#linktotoggle").click(function() {
   // ^ Attach a click event to our link
        $("#formtotoggle").toggle();
        // ^ select the form and toggle its display

   });
});

希望这足够让你开始了。

这里有更多的Codez

 <a href="#" id="yourlink">yourlink</a>
    <form id="yourform" style="display:none;">form here.</form>
    <script>
    $(document).ready(function () {
        $('#yourlink').click(function () {
            $('#yourform').css('display', 'inline');
        });
    });
    </script>

从这里开始。
$(文档).ready(函数(){
$('#yourlink')。单击(函数(){
$('#yourform').css('display','inline');
});
});

您将需要JavaScript。哦,好的,现在就这么做。。抱歉。当我单击时,它会显示表单,但当我再次单击时,它不会隐藏表单。@LucasMatos,display
inline
不会隐藏表单。使用
display='none'
执行以下操作so@LucasMatos,让我猜猜,您想在单击button@LucasMatos,我用jquery做了一个测试。希望它能帮助我,但是你能告诉我如何创建这个jquery函数吗?它像javascript还是什么?我更新了检查代码,让您了解它在点击链接时的作用(分配链接id而不是#lnk=#)
$(document).ready(function() {
// ^ This is an event, which triggers once all the document is loaded so that the manipulation is always guaranteed to run.
   $("#linktotoggle").click(function() {
   // ^ Attach a click event to our link
        $("#formtotoggle").toggle();
        // ^ select the form and toggle its display

   });
});
 <a href="#" id="yourlink">yourlink</a>
    <form id="yourform" style="display:none;">form here.</form>
    <script>
    $(document).ready(function () {
        $('#yourlink').click(function () {
            $('#yourform').css('display', 'inline');
        });
    });
    </script>