0

私はこのコード(doc)を持っています:

<!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');

});

そして+1ボタン登場!CSSがなくてもすべてが機能するため、「スタイルの競合」のように見えます!

この問題を解決するにはどうすればよいですか? ありがとう。

4

1 に答える 1

0

You need to use jQuery Mobile button widget methods to enable/disable buttons

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

$('#comment').bind('notext', function () {
  $('#commentButton').button('disable');
});
于 2013-07-20T19:24:24.840 に答える