jquery ui对话框总是返回false

时间:2012-07-18 04:56:00

标签: jquery

当您在输入中输入文本或不打开对话框时。只有在没有找到值时才会打开:fiddle = http://jsfiddle.net/tzxS2/

code / css / js:似乎不适用于表单:

 <form id="dacform" method='get' action='dac' onsubmit="return check_domain_input()" accept-charset='utf-8'>
    <input name='domain' type="text" style="font-size:15px;" class="searchbox"/>
    <select style="background:#f8f8f8; margin-left:4px; font-size:15px;" class="selectlist slight" id="selectdomain" name="tld">
      <option value=''>( all )</option>
      <option value="co.uk">co.uk</option>
      <option value="me.uk">me.uk</option>
      <option value="org.uk">org.uk</option>
      <option value="com">com</option>
    </select>
    <input onclick="check_domain_input()" class="btn grey bbig" name="search" type="submit" value="Search" style="width:59px; margin-left:7px; font-size:15px;" />
    </form><br />
    Our domain registration system is highly automated so we register your domain names fast and secure.

    <div id="dialog" title="Attention!" style="display:none">
    Please enter a domain name to search for.
    </div>
<div onclick="check_domain_input()">Click</div>

<div id="dialog" title="Attention!" style="display:none">
    Please enter a domain name to search for.
</div>

<script>
    function check_domain_input()
    {        
        $( "#dialog" ).dialog(); // Shows the new alert box.

        var domain_val = document.getElementsByName('domain');

        if (domain_val[0].value.length > 0)
        {
            return true;
        }

        $( "#dialog" ).dialog();

        return false;
    }
</script>

3 个答案:

答案 0 :(得分:1)

在我看来,你总是用函数体的第一行打开对话框:

   $( "#dialog" ).dialog(); // Shows the new alert box.

无论输入的值如何。

尝试删除该行。

答案 1 :(得分:0)

试试这个,

<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.21/themes/base/jquery-ui.css" type="text/css" media="all" />


<input type='text' name='domain'>
<div onclick="check_domain_input()">Click</div>

<div id="dialog" title="Attention!" style="display:none">
    Please enter a domain name to search for.
</div>

<script>
    function check_domain_input()
    {       

        var domain_val = document.getElementsByName('domain');

        if (domain_val[0].value.length > 0)
        {
            return true;
        }

        $( "#dialog" ).dialog(); // Shows the new alert box.
        return false;
    }
</script>

答案 2 :(得分:0)

根据您的情况,您不应该在代码中两次调用您的ui对话框。

试试这个..

<script>
function check_domain_input()
{        
var domain_val = document.getElementsByName('domain');

if (domain_val[0].value.length > 0)
  {
    return true;
  }

else
  {
    $( "#dialog" ).dialog();
    return false;
  }
}
</script>
相关问题