键入后无法在输入中动态设置文本值 [英] Cannot set dynamically text value in input after typing

查看:113
本文介绍了键入后无法在输入中动态设置文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的jquery调用,由单击编辑按钮引起,它打开带有输入(#folder-typed)的对话框,默认文本值为$ keepTitle。它工作正常,但是当我为输入键入新值,然后关闭对话框并重新打开它时,此代码的第二行就像被忽略了。文本输入的值不会改变,默认情况下它会获得我之前键入的值。

I have simple jquery call, caused by clicking "edit button", that opens dialog box with input (#folder-typed) with default text value of $keepTitle. It works fine, but when I type new value to the input, then close dialog box and re-opening it, second line of this code is like ignored. Value of text input doesn't change, and by default it gets value I typed previously.

$keepTitle = $('.nav-folder-text[pass="' + $to_edit_id + '"]').text();
$('#folder-typed').attr('value', $keepTitle);
new_f_dialog.dialog("open");

E:附加html

     <div class="name-container">
        <label for="name">Enter name:</label>
        <input class="text-input" id="folder-typed" type="text" name="title" class="text ui-widget-content ui-corner-all">
      </div>

正如我所说,点击编辑虽然有多个位置,但它正确地将默认输入值更改为传递标题,直到我用键盘改变文本输入值 - 然后它仍然是最后输入的值。

As I said, when clicking "edit" though several positions it correctly changes default input value to passed title, until I change text input value with keyboard - then it remains last typed value.

推荐答案

这不仅仅是第二行代码是忽略,一旦DOM准备就绪,它会在浏览器中加载所有包含和引用的javascripts和css,以创建所需的内容/功能。

It's not just second line of code is ignored, once the DOM is ready, it loads all the included and referenced javascripts and css in the browser to create the desired content/functionality.

你看到的是这个jquery的预期行为。每次特定输入框在页面上可见时,更改输入框的值将导致不同的值。

What you're seeing is expected behavior from this jquery. Changing the value of your input box will result in a different value everytime that particular input box will be visible on the page.

将该输入框置于编辑弹出窗口之外并更改其值。在重新加载页面或在浏览器控制台中运行javascript之前,您将无法在该文本框中获得 $ keepTitle的值。

Put that input box outside of your edit pop up and change it's value. You won't be able to get $keepTitle's value back in that text box until you re-load the page or run the javascript in the browser console.

如果您不想更改输入框的值,可以通过 $(#textBoxId)禁用文本框.attr(disabled ,禁用);

If you don't want the input box's value to be changed, you can disable the text box by $("#textBoxId").attr("disabled", "disabled");

我希望它能解释您在网页上的行为。

I hope it explains the behavior that you're getting on your page.

这篇关于键入后无法在输入中动态设置文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆