2013-07-20 46 views
0

殘疾人按鈕,我有這樣的代碼(doc):使用jQuery移動

<!DOCTYPE html> 
<html> 
<head> 
    <title>123</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /> 

</head> 

<body> 

<form> 
    <input type="text" name="comment" id="comment" placeholder="Comment" maxlength="140" value=""> 
    <div id="charactersLeft"></div> 
    <input type="submit" id="commentButton" data-icon="edit" data-inline="true" data-mini="true" data-theme="b" value="Send" disabled="disabled"> 
</form> 

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> 
<script src="http://zurb.com/playground/javascripts/plugins/jquery.textchange.min.js"></script> 

<script> 


$(document).ready(function(){ 

$('#comment').bind('hastext', function() { 
    $('#commentButton').removeAttr('disabled'); 
}); 

$('#comment').bind('notext', function() { 
    $('#commentButton').attr('disabled', 'disabled'); 
}); 

$('#comment').bind('textchange', function (event, previousText) { 
    $('#charactersLeft').html(140 - parseInt($(this).val().length)); 
}); 

}); 

</script> 
</body> 
</html> 

如果我刪除了CSS,這個工程。

在Chrome的控制檯:

$('#commentButton'); 

<input type="submit" id="commentButton" data-icon="edit" data-inline="true" data-theme="b" value="Отправить" disabled="disabled" class="ui-btn-hidden" data-disabled="true"> 

它很奇怪,因爲在HTML我還沒有得到class="ui-btn-hidden"。所以,我可以在<script>中進行一些更改:

$('#comment').bind('hastext', function() { 
    $('#commentButton').removeClass('ui-btn-hidden').removeAttr('disabled'); 

}); 

然後apears +1按鈕!看起來像「風格衝突」,因爲沒有CSS一切正常!

如何解決這個問題?謝謝。

+0

可以爲此提供一個小提琴。 – vipulsharma

+0

http://jsfiddle.net/kfDHh/嘗試在表單中寫入內容,然後刪除css並重試 – tim

回答

0

你需要使用jQuery Mobile的啓用/禁用按鈕

$('#comment').bind('hastext', function() { 
    $('#commentButton').button('enable'); 
}); 

$('#comment').bind('notext', function() { 
    $('#commentButton').button('disable'); 
}); 
+0

不工作。輸入 - 它不是一個按鈕,不?) – tim

+0

在這裏工作http://jsfiddle.net/kfDHh/2/。從文檔:「jQuery Mobile自動將任何按鈕或輸入元素與提交,重置或按鈕類型轉換爲自定義樣式按鈕」 –

+0

謝謝。你非常幫助我 – tim