2015-02-10 52 views
0

请问我可以告诉我如何给查询按钮分配一个id。我使用的查询对话框模式窗体(http://jqueryui.com/dialog/#modal-form) - 试图样式的按钮,但它不工作JQUERY分配id给jquery对话框按钮

我的查询代码:

buttons: { 
     "Create an account": addUser, 
     Cancel: function() { 
     dialog.dialog("close"); 
     } 
    }, 

我尝试添加它作为以下,但它没有工作:

buttons: { 
     "Create an account": { addUser, 
     id: "account-btn" 
     Cancel: function() { 
      dialog.dialog("close"); 
     } 
     } 
    }, 
+0

如果你想样式的按钮来添加身份证在你的HTML。在你提供的那个链接上,如果你点击查看源代码,然后滚动到最下面你会看到按钮id在html – Craicerjack 2015-02-10 23:22:36

+0

中设置,“创建帐户”按钮不会显示 - 这是一个隐藏的按钮,我不确定如何访问和风格。你指的是“创建新用户”按钮,但我在寻找“创建一个帐户按钮”,以添加一个ID来设计它的样式 – ARTLoe 2015-02-10 23:28:51

+0

对不起,没有看到。实际上看你的代码你做了一些奇怪的按钮 - 回答下面添加 – Craicerjack 2015-02-11 10:47:57

回答

0

他们有一类ui-button。所以,你可以只瞄准他们在CSS像这样:

.dialogForm > .ui-button { 
    /* styles here */ 
} 

或针对特定的按钮

.dialogForm > .ui-button:nth-of-type(1) { 
    /* targets the first button */ 
} 

同样可以用JS针对他们并添加类,但它的混乱。

  • 编辑:如果您试图添加样式的id,请考虑使用类代替。不过,您可以在第一个按钮上添加一个ID。这是jQuery模式为按钮视图创建的标记。

$(function() { 
 
    // If you want to target another button use 'button.ui-button:nth-child(INT)'. 
 
    // Remove the selector and colon if you wish to target both. 
 
    var $button = $('div.ui-dialog-buttonpane button.ui-button:first'); 
 

 
    // Adds id attribute. The styling here is just to prove we're getting the right thing. 
 
    $button.attr('id', 'uglyId'); 
 
    $button.css('background-color', 'pink'); 
 

 
    console.log($button.attr('id')); 
 
}());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <script src="//code.jquery.com/jquery-2.1.1.min.js"></script> 
 
    <meta charset="utf-8"> 
 
    <title>JS Bin</title> 
 
</head> 
 

 
<body> 
 
    <div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"> 
 
    <div class="ui-dialog-buttonset"> 
 

 
     <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"> 
 
     <span class="ui-button-text">Create an account</span> 
 
     </button> 
 
     <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"> 
 
     <span class="ui-button-text">Cancel</span> 
 
     </button> 
 

 
    </div> 
 
    </div> 
 

 
</body> 
 

 
</html>

+0

我正在寻找一个特定的按钮,并想知道如何分配一个id到该特定的按钮,因为它的造型是不同于其他按钮 – ARTLoe 2015-02-11 00:01:09

+0

回答。仅供参考,请使用DevTools或Firebug查看HTML标记。然后,您可以决定哪些元素具有可以绑定的道具。 – 2015-02-11 00:46:49

0

你正在创建的按钮中的一个对象,并试图将ID添加到,而不是添加id来按钮。尝试这个。

buttons: { 
    id: "account-btn", //id as a seperate attribute 
    "Create an account": addUser, 
    Cancel: function() { 
      dialog.dialog("close"); 
    } 
} 

或给予相应的ID只为造型,你可以这样做:
给你的对话形式的ID,然后在你的CSS

#dialog_form_id button { 
    //add your style here 
}