繁体   English   中英

jQuery 可以更改输入提交类型的文本但按钮不再可点击

[英]jQuery can change the text of input submit type but button is no longer clickable

我正在使用 jaquery 和 jquery 移动版 1.8,我有一个像这样的按钮:

   <div class="ui-bar-a" id="myButton" style="bottom:0;position: fixed;width: 100%">
        <input type="submit" name="Next" id="NextButton" value="Save"  /> 
   </div>

我有一个 javascript 可以像这样更改它的文本:

     $('#AnyButton').live('click', function() {             
        if(true)
        {
            $('#myButton div').text('Saving')
        }
        else
            $('#myButton div').text('Continue');
    });

我尝试了许多其他不起作用的方法,但这有效,但是在我更改文本后,按钮似乎将 myButton div 内容替换为文本“保存”或“继续”,因此该按钮不再可点击。

在我的浏览器调试器中,按钮会在 myButton 和 Nextbutton 输入之间显示一个文本 Save。

像这样:

<div class="ui-bar-a" id="myButton" style="bottom:0;position: fixed;width: 100%">
"Save"
      <input type="submit" name="Next" id="NextButton" value="Save"  /> 
</div>

如果我正确阅读了您的帖子,您想更改输入的文本,您需要更改它的 value 属性。 我认为.live相对较旧且已弃用,应替换为.on和委托的事件处理程序

$('#AnyButton').live('click', function() {             
    if(true)
        $('#myButton').find('input[type="submit"]').val('Saving');
    else
        $('#myButton').find('input[type="submit"]').val('Continue');
});

我怀疑您的代码比您提供的更多。 对于 jQuery Mobile,每个input都被读取为一个按钮。 所以你可能需要在动态更新后刷新它。

此代码有效:

 $(function() { $("#NextButton").click(function(e) { e.preventDefault(); $(this).val("Saving").button("refresh"); }); });
 <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <div class="ui-bar-a" id="myButton" style="bottom:0;position: fixed;width: 100%"> <input type="submit" name="Next" id="NextButton" value="Save" /> </div>

查看更多: https://api.jquerymobile.com/button/https://demos.jquerymobile.com/1.4.5/button/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM