jQuery Mobile Button启用/禁用&更改后TextArea自动重新调整大小

时间:2011-05-01 19:22:51

标签: button textarea jquery-mobile

  • 如何禁用/启用按钮?在navBar中,它不是一种形式。我试过一些例子,都失败了。

  • 我正在更改我的textarea文本$("textarea").val(x);文本正在改变,问题是它没有自动重新调整大小,我看到侧面的丑陋滚动条,如果我手动调整大小,它的确定...是否有强制刷新的方法或类似的东西?

由于

更新(TextArea):

如果我单击文本区域然后按任意键 - >它应该是开放的, 我试图模拟它..但失败,绑定是有效的,但是按键/ keydown的触发器没有,我尝试使用谷歌搜索的一些代码,这应该工作,我认为,mayb for nomral jQuery 1.6,但不是jQuery mobile ..我的测试是在Chrome和iPhone 4上

$('#textarea').bind('click', function() {
    var e = jQuery.Event("keypress", { keyCode: 64 });
    $(this).trigger( e );
});

2 个答案:

答案 0 :(得分:2)

更新:

链接按钮示例:

JS

var clicked = false;

$('#myButton').click(function() {
    if(clicked === false) {
        $(this).addClass('ui-disabled');
        clicked = true;
        alert('Button is now disabled');
    } 
});

$('#enableButton').click(function() {
    $('#myButton').removeClass('ui-disabled');
    clicked = false; 
});

HTML

<div data-role="page" id="home">
    <div data-role="content">

        <a href="#" data-role="button" id="myButton">Click button</a>
        <a href="#" data-role="button" id="enableButton">Enable button</a>

    </div>
</div>

注意: - http://jquerymobile.com/demos/1.0rc2/docs/buttons/buttons-types.html

  

类似按钮的链接具有与true相同的所有可视选项   下面是基于表单的按钮,但有一些重要的区别。   基于链接的按钮不是按钮插件的一部分,只是使用   底层的buttonMarkup插件生成按钮样式   不支持表单按钮方法(启用,禁用,刷新)。   如果你需要禁用基于链接的按钮(或任何元素),那就是   可以自己应用残疾人ui-disabled   JavaScript实现同样的效果。

答案 1 :(得分:1)

关于你的第二个问题,你可以通过触发一个keyup()事件来使textarea自动增长。

考虑到您的原始示例代码,以下内容适用于我:

/*Note: I'm using 'on' instead of 'bind', because that's what I've actually tested 
with, but I'm pretty sure this will work with 'bind' as well*/
$('#textarea').on('click', function() {
    //First we'll add some text to #textarea
    $('#textarea').val('some dummy text to be added to the textarea');
    //Then we trigger keyup(), which causes the textarea to grow to fit the text
    $('#textarea').keyup();
});

以上简短而甜蜜的版本,这次链接并且没有评论:

$('#textarea').on('click', function() {
    $(this).val('some dummy text to be added to the textarea').keyup();
});

改编自here