【问题标题】:cant display the input value using jquery. I tried to get the value but there is nothing to show-up pls help me. thanks无法使用 jquery 显示输入值。我试图获得价值,但没有什么可以显示的,请帮助我。谢谢
【发布时间】:2017-03-06 12:33:13
【问题描述】:

这是我的代码:

var nameid = $("#idname").val();
var fname = $("#fname").val();
var loc = $("#loc").val();

这是输入:

<input type="text" name="fname"  id="fname" />
<input type="text" name="loc"  id="loc" />

当我提醒两个输入值时,它将返回空。

【问题讨论】:

  • 您是否等待实际输入的内容?
  • 是的,我有来自服务器的数据,当我将数据放入输入文本中时,当我提醒或显示两个输入的值时,该值为空。
  • 我得到了答案.. 谢谢

标签: jquery input


【解决方案1】:

您的代码正在运行。

HTML:

<input type="text" name="fname"  id="fname" />
<input type="text" name="loc"  id="loc" />
<button id="btn">
Show entered
</button>

Js:

$("#btn").on("click", function(e){
    var fname = $("#fname").val();
    var loc = $("#loc").val();
    alert('fname='+fname);
  alert('loc='+loc);
});

检查jsFiddle

【讨论】:

    【解决方案2】:
    <input type="text" name="fname"  id="fname" value="1" />
    <input type="text" name="loc"  id="loc" value="2" />
    $(function(){
    var nameid = $("#idname").val();
    var fname = $("#fname").val();
    var loc = $("#loc").val();
    alert(fname);
    alert(loc);
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-06
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      相关资源
      最近更新 更多