2011-12-07 233 views
0

下面是我的html页面,其中包含一个按钮。在我的按钮input.ui-button {padding:0.4em 1em; }风格被添加到按钮。它是从jquery-ui.css中加入的。我必须添加在线更改填充值。但我无法按照指示添加此内容。请建议我是否有其他方式来设置这些值,而不是内嵌样式。在jquery中更改css属性

 <body> 
     <input type="button" onclick="javascript:submitForm('reset');" class="ui-button- default ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" 
     value="Reset"> 
     </body> 
+4

你应该有一个单独的CSS无论如何。内联CSS通常是一个坏主意。当你完成了排序后,你可以在jQuery中使用'.css()'方法。 – Polynomial

+1

你在代码中使用jQuery.js吗?你为什么还在使用onclick? –

+0

感谢多项式,我已经将它添加到单独的.css文件中,但它不反映,直到我添加它像内联。 – Raj

回答

2

尝试像

<body> 
    <input type="button" id="btn" value="Reset"> 
    </body> 

在Javascript中:

$('#btn').button();     // to apply the default css style of the jQuery UI boutton 
$('#btn').css({'margin-left':'20px'}); // to modify the css of the element 
$('#btn').click(function(){ 
    // This function is called when the bouton is clicked 
}); 
+0

'$('#btn').css('margin-left':'20px');'是错误的语法。 –

+0

@ShadowWizard谢谢。它现在是固定的 –

+0

干杯,也请将“boutton”更改为“button”。 :) –

1

只需添加自己的样式表重写.ui-button填充定义:

<style type="text/css"> 
    .ui-button { padding: 0; } 
</style>