2012-07-18 62 views
0

當你輸入文本或不輸入對話框時,打開對話框。如果沒有價值發現只能打開:小提琴= http://jsfiddle.net/tzxS2/jquery ui對話框總是返回false

碼/ 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> 

回答

1

在我看來,你是始終在打開對話框,您的功能正文的第一行:

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

不管輸入的值如何。

嘗試刪除該行。

+0

耶曾在撥弄但活着不是??? – david 2012-07-18 05:12:11

+0

刪除該行後,您得到的確切行爲是什麼? – 2012-07-18 20:14:32

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> 
+0

它只是懶惰不添加「其他」或不重要嗎? – david 2012-07-18 05:31:23

+0

使用else是一個好習慣,但是在這裏我們可以節省帶寬:D – Matt 2012-07-18 05:42:43

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> 
+0

小提琴更新仍然不起作用http://jsfiddle.net/tzxS2/ – david 2012-07-18 05:38:27

+0

不得不打電話域!總是最小的東西 – david 2012-07-18 05:45:25

+0

我曾試圖在小提琴上,它工作正常。 – Rohit416 2012-07-18 12:01:28