本文介绍了帮助"hello world" jquery-ui模态形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jquery ui显示模式形式.我已经改编了一个示例,但无法启动对话框.我敢肯定这很简单,但是有人可以告诉我我在做什么错吗?

I'm trying to display a modal form using jquery ui. I've adapted an example but I cannot get the dialog to launch. I'm sure it's very simple but can someone tell me what I'm doing wrong ?

页面最初显示,但是当我单击创建新用户"时,没有任何反应.

The page displays initially but when I click on 'Create New User' nothing happens.

下面的代码-也(易于阅读)位于 http://pastie.org/1000263

The code is below - also (easier to read) at http://pastie.org/1000263 .

<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>jQuery UI Example Page</title>
  <link type="text/css" href="jquery-ui-1.7.3.custom/css/smoothness/jquery-ui-1.7.3.custom.css" rel="stylesheet" /> 
  <script type="text/javascript" src="jquery-ui-1.7.3.custom/js/jquery-1.3.2.min.js"></script>
  <script type="text/javascript" src="jquery-ui-1.7.3.custom/js/jquery-ui-1.7.3.custom.min.js"></script>
  <script type="text/javascript">
  $(function(){
   $("#dialog-form").dialog({
    autoOpen: false,
    height: 300,
    width: 350,
    modal: true,
    buttons: {
     'Create an account': function() {
      var bValid = true;
      allFields.removeClass('ui-state-error');

      if (bValid) {
       alert(name.val());
       $(this).dialog('close');
      }
     },
     Cancel: function() {
      $(this).dialog('close');
     }
    },
    close: function() {
     allFields.val('').removeClass('ui-state-error');
    }
   });

   $('#create-user')
    .button()
    .click(function() {
     $('#dialog-form').dialog('open');
    });


  });
  </script>

  <style type="text/css">
   /*demo page css*/
   body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
   .demoHeaders { margin-top: 2em; }
   #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
   #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
   ul#icons {margin: 0; padding: 0;}
   ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
   ul#icons span.ui-icon {float: left; margin: 0 4px;}
  </style> 
 </head>
 <body>
 <h1>Welcome to jQuery UI!</h1>

 <p style="font-weight: bold; margin: 2em 0 1em; font-size: 1.3em;">YOUR COMPONENTS:</p>
   <div id="dialog-form" title="Create new user">
    <p class="validateTips">All form fields are required.</p>

    <form>
    <fieldset>
     <label for="name">Name</label>
     <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
     <label for="email">Email</label>
     <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
     <label for="password">Password</label>
     <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
    </fieldset>
    </form>
   </div>  
   <button id="create-user">Create new user</button>
 </body>
</html>

推荐答案

删除.button()

Your code worked fine when I removed .button()

   $('#create-user')
    .click(function() {
     $('#dialog-form').dialog('open');
    });

我不太确定.button()到底做什么.我不确定我以前是否看过.

I'm not really sure what .button() does anyways. I'm not sure I've seen it before.

Chrome浏览器中的javascript控制台说:未捕获的TypeError:对象#没有方法'button'"

The javascript console in chrome said:"Uncaught TypeError: Object # has no method 'button'"

javascript控制台对于为什么事情不起作用"将非常有用.

The javascript console will be very useful for "why things don't work".

这篇关于帮助"hello world" jquery-ui模态形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 08:51