jQuery Mobile:.val()无法正常工作 [英] JQuery Mobile: .val() not working

查看:138
本文介绍了jQuery Mobile:.val()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我有以下jQuery Mobile代码:

I have the following jQuery Mobile code:

<div data-role="content">
  A confirmation code has been sent to your mobile phone via SMS
  <br><br>
  To proceed, please enter the 3-digit confirmation code below:
  <br>
  <input id="verifySMS_code" type="text"  /><br>
  <a id="verifySMS_submit" href="#" data-role="button">Submit</a>
</div>

这是我的JavaScript:

Here is my javascript:

$(document).ready(function(){
  $("#verifySMS_submit").live("click",function() {
    alert('hi');
    var code=$('input#verifySMS_code').val();
    alert(code);
  });
});

'hi'出现在第一个警报框中,而''出现在第二个警报框中-即完全空白!

'hi' appears in the first alert box, however '' appears in the second alert box - i.e. totally blank!!!

我也尝试了document.getElementById('verifySMS_code'),但无济于事.

I've tried document.getElementById('verifySMS_code') too to no avail.

我什至尝试了jquery mobile 1.0a3pre

I've even tried jquery mobile 1.0a3pre

对我来说这是一个非常严重的问题,我不知道如何解决.

This is a really serious problem for me and I've no idea how to fix it.

我希望有人能提供帮助.

I hope someone can help.

在此先感谢

推荐答案

  1. 安装firebug

  1. Install firebug

<input id="verifySMS_code" type="text" value="someoldvalue" />

$(document).ready(function(){
  $("#verifySMS_submit").bind("submit",function() {
    console.log($('#verifySMS_code'));
    var code=$('#verifySMS_code').val();
    console.log(code);
  });
});

这是为什么:

    输入中的
  • value=将显示 如果这是一个问题 价值或输入内容 到输入元素(jQuery Mobile 在输入上构建一些东西)
  • 您将不会生成与"#verifySMS_submit"匹配的新提交按钮 因此您在那里不需要live()
  • 通过单击并提交来尝试.我想jQuery Mobile正在 从输入控件到 在某些时候输入自己 就像输入中的blur事件一样,因此 当您单击某物时发生 其他,不是在那之前
  • console.log($('input#verifySMS_code')); 将在控制台中弹出您的元素. 如果弹出空数组-没有 这样的元素,它是一个选择器 问题.
  • the value= in the input will show if it's a problem with getting the value or with putting what you enter into the input element (jquery mobile builds something on the input)
  • you will not generate new submit buttons matching "#verifySMS_submit" so you don't need live() there
  • try it with click and with submit. I suppose jquery mobile is putting text from the input control to the input itself at some certain moments like blur event on the input, so it happens when you click something else, not before that
  • console.log($('input#verifySMS_code')); will pop up your element in console. if empty array pops up - there was no such element and it's a selector problem.

测试具有重复ID的输入.

Test for inputs with duplicated IDs.

这将显示所有ID:$('input').each(function(){console.log($(this).attr('id'));}); 在firebug中运行它,它还将指向DOM,因此您可以在HTML选项卡中单击并找到它们.

This shows all ids: $('input').each(function(){console.log($(this).attr('id'));}); Run it in firebug and it will also point to DOM so you can click and find them in HTML tab.

这篇关于jQuery Mobile:.val()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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