2015-04-26 35 views
1

我无法在调用onClick函数时更改div的css属性。如何使用引导按钮和窗体内部调用onClick javascript函数?

<h1 id="hello">hello</h1> 

<div id="notification" class="alert alert-dismissible alert-success"> 
    <button type="button" class="close" data-dismiss="alert">×</button> 
    <strong>Well done!</strong> You successfully posted to Facebook! 
</div> 

<div align="center" class="col-sm-4"> 
    @using (Html.BeginForm("distShare", null, new { area = "" })) 
    { 
     <button onclick="facebookButton2()" class="btn btn-primary" type="submit">Share this to Facebook</button> 
    } 
</div> 
function facebookButton2() { 
    document.getElementById("notification").style.visibility = visible; 
    document.getElementById("notification").style.color = red; 
    document.getElementById("hello").style.color = red; 
} 

的 “你好” 只是用于测试目的。我也尝试过使用JQuery和onSubmit函数。通知div以可见性开始:隐藏。

+0

'''@'''符号之间发生了什么? –

回答

1

我猜你是路过应该是字符串值,我真的怀疑你已声明的JavaScript变量称为visiblered在你的页面的任何地方:

function facebookButton2() { 
    document.getElementById("notification").style.visibility = 'visible'; 
    document.getElementById("notification").style.color = 'red'; 
    document.getElementById("hello").style.color = 'red'; 
} 
+0

谢谢!这是XD问题的一部分 –

0

更改功能:

function facebookButton2() { 
    document.getElementById("notification").setAttribute('style','visibility:visible'); 
    document.getElementById("notification").setAttribute('style','color:red'); 
    document.getElementById("hello").setAttribute('style','color:red'); 
} 

看到在这里工作:http://jsbin.com/rosubazuna/1/

0

发现问题。

“distShare”在我的控制器中调用了distShare()方法,该方法使我返回到“新”视图,即使它是相同的页面。我基本上刷新了页面。所以它在技术上工作,我只是没有意识到这一点。但是,我也必须像Darin Dimitrov所说的那样将这些值改为字符串。谢谢你的帮助!

相关问题