2013-01-11 317 views
0

Problem- 按钮颜色没有改变, 我用jQuery的点击功能按钮颜色不改变

<button class="red" id="MyQuotes" href="#" title="">@Aceo.Crm.App.Resources.Shared.Order.Link_MyQuote</button> 

此按钮,我用jQuery的作为

$(document).ready(function(){ 
    $("#MyQuotes").click(function(){ 
    $(this).css({background:"red"}); 
    }); 
}); 

,但它不是全成,我试图以这种方式做到这一点 -

<button class="red" onclick="D()" id="MyQuotes" href="#" title="">@Aceo.Crm.App.Resources.Shared.Order.Link_MyQuote</button> 

我做了java脚本功能在这里 -

<script language="javascript"> 
function D() 
{ 
document.body.style.backgroundColor="red"; 
} 
</script> 

而且这次我又失败了。 你能给我推荐一些代码吗?

+0

Hey Manoj,欢迎来到SO。你可以做一个http://jsfiddle.net这个,所以我们可以看到,并从中修改? – fedmich

+0

好的,我会做小提琴 – Manoj

回答

2

使用jQuery:http://jsfiddle.net/DrWjq/

$(document).ready(function(){ 
    $("#MyQuotes").click(function(){ 
    $(this).css({background:"red"}); 
    }); 
}); 

纯JS:http://jsfiddle.net/wx9tw/

function D(id) 
{ 
id.style.backgroundColor="red"; 
} 

<button class="red" onclick="D(this)" id="MyQuotes" href="#" title="">@Aceo.Crm.App.Resources.Shared.Order.Link_MyQuote</button> 
+0

+1好点!!! –

+0

这没有发生,它只给闪光红色,没有别的 – Manoj

+0

我的错误,选择的id是“#Myquotes”,但没有得到需要。 – Manoj

1

您选择的ID是 “MyQuotes”,而不是 “MyOrders”

试试这个

$("#MyQuotes").click(function(){ 
    $(this).css({background:"red"}); 
}); 

OR

function D() 
{ 
    $('#MyQuotes').css({background:"red"}); 
} 
0

您必须参考该按钮(SO #MyQuotes不#MyOrders)在JS:

$(document).ready(function(){ 
    $("#MyQuotes").click(function(){ 
    $(this).css({background:"red"}); 
    }); 
}); 
0

您可以使用$(this).css("background-color","red");(和目标正确元素的id)

fiddle