Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想将文本存储在javascript变量的p标记下,然后显示在输入字段中_Javascript_Jquery_Html - Fatal编程技术网

我想将文本存储在javascript变量的p标记下,然后显示在输入字段中

我想将文本存储在javascript变量的p标记下,然后显示在输入字段中,javascript,jquery,html,Javascript,Jquery,Html,我希望将文本存储在javascript变量的p标记中,然后文本显示在输入字段中 <p id="txt" onclick="check();">yes i am stroe in js variable</p> <input id="show" type="text" name="" disabled=""> <script type="text/javascript"> function check() { var input =

我希望将文本存储在javascript变量的p标记中,然后文本显示在输入字段中

<p id="txt" onclick="check();">yes i am stroe in js variable</p>
<input id="show" type="text" name="" disabled="">

    <script type="text/javascript">
function check() {
    var input = document.getElementById("txt").text;

    document.getElementById("show")=input.value;
}
</script>
是的,我是js变量中的stroe

函数检查(){ var input=document.getElementById(“txt”).text; document.getElementById(“show”)=input.value; } document.getElementById('show')。值=输入

看到这个了吗 要获取
中的内容,必须使用
innerHTML
而不是
value

在中阅读有关innerHTML的更多信息

因此,您的
脚本应重写为

function check() {
    var input = document.getElementById("txt");
    document.getElementById("show").value=input.innerHTML;
}
函数检查(){
var input=document.getElementById(“txt”);
document.getElementById(“show”).value=input.innerHTML;
}
是的,我是js变量中的stroe

html:

<p id="PTag">Hello :D</p>
<a id="Btn">click me</a>

你好:D

点击我
在脚本中使用文本

<script>
  $('#Btn').click(function () {
     var hello= $("#PTag").html($("#text").val())[0].innerHTML; 
     alert(hello)
  })
</script>

$('#Btn')。单击(函数(){
var hello=$(“#PTag”).html($(“#text”).val())[0];
警报(你好)
})
结果 ======>>>>
您好:D

您刚刚在错误的位置放置了
.value
document.getElementById(“show”).value=input
另外,
p
元素没有
文本
;它们有
innerHTML
innerText
/
textContent
。投票以打字错误/不重复/对将来的其他人不有用的方式结束您已经标记了问题,但没有在其中使用任何jQuery。您确定需要/想要使用jQuery吗?