简体   繁体   English

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

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

I am using jaquery and jquery mobile version 1.8 and I have a button like so:我正在使用 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>

And I have a javascript that can change the text for it like so:我有一个 javascript 可以像这样更改它的文本:

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

I tried so many other ways that didn't work but this works however after I change the text the button seems to replace the myButton div content with the text Saving or Continue and thus the button is no longer clickable.我尝试了许多其他不起作用的方法,但这有效,但是在我更改文本后,按钮似乎将 myButton div 内容替换为文本“保存”或“继续”,因此该按钮不再可点击。

In my browser debugger the button shows a text Save appear between myButton and the Nextbutton input.在我的浏览器调试器中,按钮会在 myButton 和 Nextbutton 输入之间显示一个文本 Save。

Like so:像这样:

<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>

If I am reading your post correctly, you want to change the text of the input, you need to change it's value property.如果我正确阅读了您的帖子,您想更改输入的文本,您需要更改它的 value 属性。 I think .live is relatively old and deprecated and should be replaced with .on and a delegated event handler我认为.live相对较旧且已弃用,应替换为.on和委托的事件处理程序

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

I suspect there is more to your code than you have presented.我怀疑您的代码比您提供的更多。 With jQuery Mobile, each input is read as a Button.对于 jQuery Mobile,每个input都被读取为一个按钮。 So you mnay need to refresh it after a dynamic update.所以你可能需要在动态更新后刷新它。

This code is working:此代码有效:

 $(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>

See More: https://api.jquerymobile.com/button/ and https://demos.jquerymobile.com/1.4.5/button/查看更多: 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