这两个jQuery语句中没有错误,但我只是想知道为什么

There is no bug in those two jQuery statements but I am just wondering why

本文关键字:有错误 为什么 想知道 两个 语句 jQuery      更新时间:2023-09-26

以下工作完美

sendtext5 = "Homer Simpson";
$eraser.prop('value', sendtext5);
$.mobile.pageContainer.pagecontainer( "change", $article2 );

但不是以下

sendtext5 = "Homer Simpson";
$.mobile.pageContainer.pagecontainer( "change", $article2 );  // This line executes
$eraser.prop('value', sendtext5);   // This line does not execute 

$article 2 是div 标签,$eraser 是输入标签。

我想知道为什么第二种情况有效,但第一种情况有效。

它是jQuery 2.1.1和jQuery Mobile 1.4.5

非常感谢,堆栈溢出!

我假设$eraser$article2中的一个元素。 如果不是,那么这个答案可能毫无价值。

在第一个示例中,您将在 JQM 增强布局之前设置属性。

在第二个示例中,您将在增强布局后对其进行设置。 这意味着您正在更改 value 属性,但在基础窗体元素上。 您需要告诉 JQM 重新渲染显示的元素。

如果$eraser是文本框,请尝试以下操作:

sendtext5 = "Homer Simpson";
$.mobile.pageContainer.pagecontainer( "change", $article2 ); // This line executes
$eraser.prop('value', sendtext5);   // This line does execute, just on the underlying element
$eraser.textinput( "refresh" ); // This line refreshes the displayed element with the underlying elements's properties