2012-11-13 75 views

回答

1

首先你的代碼不模糊的功能,因爲工作的按鈕 點擊事件之前會火,所以我變成這個

HTML

<form method="post" action="" onsubmit="return false;"> 
    <div id="vsetko"> 
     <textarea id="scontent"></textarea> 
     <div id="sbutton_block" style="display:none;"> 
      <input type="submit" id="sbutton" value=" Share " /> 
     </div> 
    </div> 
</form>​​​​ 

CSS

#scontent { 
    overflow: auto; 
    width:722px; 
    height:30px; 
    border:solid 2px #006699; 
    font-size:14px; 
} 

#sbutton{ 
    background-color:#006699; 
    color:#ffffff; 
    font-size:13px; 
    font-weight:bold; 
    padding:4px; 
    margin-bottom: 5px; 
} 

JQUERY

$(document).ready(function(){ 

    $("#scontent").focus(function(){ 
    $(this).animate({"height": "85px",}, "fast"); 
    $("#sbutton_block").slideDown("fast"); 
    return false; 
    }); 

    $("html").click(function(event){ 
    if ($(event.target).attr("id") != "scontent") { 
     $("#scontent").animate({"height": "30px",}, "fast"); 
     $("#sbutton_block").slideUp("fast"); 
     return false; 
    } 
    }); 

    $("#scontent").keypress(function(){ 
    var MaxLen = 250; 
    return ($(this).val().length <= MaxLen); 
    }); 

    $("#sbutton").click(function(){ 
    // do your stuff 
    return false; 
    }); 

}); 

所以整個HTML click事件將取代焦點事件,那麼你可以做保存數據
我在我的筆記本電腦已經測試它的正常工作

編輯: 我是修改HTML點擊功能檢查要跳過的元素

+0

謝謝你的回答!由於某種原因,如果我點擊網站上的任何地方,文本框就會改變它的大小,而不是如果在textarea中。釋放鼠標按鈕後,提交按鈕消失。 – Mark

+0

答案已更新,http://jsfiddle.net/MgLa6/1/在線檢查 – Kotzilla

+0

嗨!此代碼禁用頁面上的所有鏈接:$(「html」)。click(function(event){if($(event.target).attr(「id」)!=「scontent」){ $ (「#scontent」)。animate({「height」:「30px」,},「fast」); $(「#sbutton_block」)。slideUp(「fast」); return false; } }) ;我該如何解決這個問題? – Mark

1

你必須註釋掉該行:

$("#sbutton_block").slideUp("fast"); 

,並在action屬性,你必須寫一個PHP頁面的名義發佈變量。

這是您的修改代碼。 http://pastebin.com/LR4HyHv6

希望它有幫助。

+0

謝謝您的快速回答。對於一些租賃它不能正常工作。 – Mark