【问题标题】:input type in javascriptjavascript中的输入类型
【发布时间】:2015-01-30 15:14:51
【问题描述】:
var input0=prompt("Please enter your name:");
while (!isNaN(input0))
{
alert("Please enter a valid name")
var input0=prompt("Please enter your name:");


enter code here
}

var o=(input0); 

var salesperson;
salesperson= input0;
document.getElementById("salesperson").value="o"
document.write ("Hello" + "<input id=>" +  +input0 "<input disabled=disabled>" )

所以这是我在 javascript 中使用的代码,因为我希望输入框仅在提示时出现。但是,我无法在输入框中得到结果salesperson,有什么帮助吗?

【问题讨论】:

  • 你想达到什么目的?此外,您的代码中似乎存在语法错误。你能在 jsfiddle 中自己尝试一下吗?
  • prompt 的结果总是一个字符串,所以它不能是NaN
  • 只是在输入框中显示的结果,但当然是使用javascript

标签: javascript checkbox input box


【解决方案1】:

基本上,您必须修复您上次的document.write 呼叫:

var input0=prompt("Please enter your name:");
while (!isNaN(input0))
{
alert("Please enter a valid name")
var input0=prompt("Please enter your name:");
}

var o=(input0); 

var salesperson;
salesperson= input0;
//document.getElementById("salesperson").value="o"
document.write ("Hello" + "<input value='" + input0 + "' disabled=disabled>" )

但是,也许您可​​以考虑设置现有输入的值,而不是使用document.write。例如:使用

document.getElementById("name").value=input0;

演示:http://jsfiddle.net/x6nkyjdc/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    相关资源
    最近更新 更多