简体   繁体   English

jquery-mobile:无法在对话框中更改输入值

[英]jquery-mobile: Can't change input value in dialog

I'm having trouble dinamicaly setting the value of textboxes on a dialog opened by a listview item with JQueryMobile. 我在使用JQueryMobile的listview项打开的对话框上设置文本框的值时遇到麻烦。

I can change the value, verified by alert before and after, but the value displayed doesn't change. 我可以更改值,通过警告前后验证,但显示的值不会更改。

The concept is a listview displaying the items of a shopping list. 该概念是显示购物清单项目的列表视图。 If the user clicks one of the items a dialog should be displayed with a form for editing the product information. 如果用户单击其中一个项目,则应显示一个对话框,其中包含用于编辑产品信息的表单。

I started by setting the href to the dialog page, and binding to the onclick event. 我首先将href设置为对话框页面,然后绑定到onclick事件。 The problem was that the event ran before the page loaded so no items where available. 问题是该事件在页面加载之前运行,因此没有可用的项目。

Next I opened the dialog programaticaly on the "onclick" event. 接下来,我打开了关于“onclick”事件的programaticaly对话框。

I can change the value, but the change isn't displayed. 我可以更改值,但不会显示更改。

Relevant Snippets are bellow. 相关的片段如下。

Thanks in advance for any help. 在此先感谢您的帮助。

Best Regards 最好的祝福

Joao 若昂

<ul data-role="listview" data-inset="true" data-split-theme="b" data-split-icon="star" id="shopping_list_listview" style="margin-bottom:0px"> 
<li>
     <a data-rel="dialog" data-transition="pop" href="#" onClick="loadData($(this))">
        <span class="product_name truncate" SAMPLE product</span>
     </a>
</li>

function loadData(obj)
        {

          $.mobile.changePage('product_dialog.html','pop',false,true) 

          var name = obj.find("span.product_name").text();

          alert ($("#popup-product-name").val());

          $("#popup-product-name").val(name);

          alert ($("#popup-product-name").val());

        }

Do it this way, here is an example. 这样做,这是一个例子。

Working Demo 工作演示

Markup 标记

<!-- Page -->
<div data-role="page" id="p1">
 <p>Click on the text box to open dialog</p>
 <input type="text" id="two" /> <a data-role="button" href="#" id="btn">Move data to dialog</a>
</div>
<!-- /Page -->

<!-- Dialog -->
<div data-role="page" data-rel="dialog" id="dialog" data-theme="c" data-close-btn="right">
 <div data-role="header" data-position="fixed" data-theme="b">
  <h1>New values added!</h1>
 </div>

 <ul data-role="listview" id="list">
  <li><a href="#">old value</a>
  </li>
  <li><a href="#">some value</a>
  </li>
  <li><a href="#">text</a>
  </li>
 </ul>
</div>
<!-- /Dialog -->

Code

$(document).on('click', 'a#btn', function () {
 var value = $("#two").val();
 $.mobile.changePage("#dialog", {
    role: "dialog"
 });
 $('#list').find('a').text(value);
});

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

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