jQuery UI Dialog, How to change text once the dialog is opened

不打扰是莪最后的温柔 提交于 2019-12-11 12:10:05

问题


I'd like to click a button in a dialog and change the text on the message area before running the function associated with the button or simply change the text as part of the function.


回答1:


You can use a .onclick event as such...

<div id="targetSelector">Click Me</div>
<div id="messageAreaSelector"></div>

//jquery code to attach click to targetSelector
$('#targetSelector').click(function() {
  //code to update message area 
  $('#messageAreaSlector').html("Text to tell user"); 
  //call to function you want to perform 
  CallSelfDefinedFunction(arguments); 
});



回答2:


Just put a text area into the dialog, it will be editable. If you want to toggle whether or not you can edit it just add a button.

(function ($) {
    var $dialog = $('<div></div>')
                    .html('<textarea id="myContent" rows=7 cols=25>Edit me</textarea>')
                    .dialog({
                        autoOpen: false,
                        title: 'editable dialog',
                        buttons: {
                            "Edit": function () { $("#myContent").attr("disabled", !$("#myContent").attr("disabled")); }
                        },
                        height: "auto",
                        width: "auto"
                    });

    $('.dlog').click(function () {
        $dialog.dialog('open');
        return false;
    });
})(jQuery);



回答3:


You can bind a function to the close event - http://jqueryui.com/demos/dialog/#event-close. I'm betting you can change your text in there.



来源:https://stackoverflow.com/questions/3336915/jquery-ui-dialog-how-to-change-text-once-the-dialog-is-opened

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!