简体   繁体   English

如何获取输入字段的值并将其显示在对话框中?

[英]How do I get the value of input fields and display it on the dialog box?

<dialog>

label id="show" label

label id="show1" label

</dialog>

var x = document.getElementById("name").value;
x = document.getElementById("show").innerHTML;

var y = document.getElementById("matrix").value;
y = document.getElementById("show1").innerHTML;

I used label form with only id="" and without for="" is it valid? 我仅使用id=""而没有for=""标签形式有效吗?

Also i'm trying to get the id(value) of the input and display it on the dialog box, is this the correct code to get it? 我也试图获取输入的id(值)并将其显示在对话框上,这是获取它的正确代码吗?

I used this code but failed to display the output on dialog box .. I'm still new in javascript 我使用了这段代码,但未能在对话框上显示输出。。

Please make your question more clear. 请让您的问题更清楚。 Do you want to get text of label control? 是否要获取标签控件的文本?

If yes then you can use below jquery code :- 如果是的话,你可以使用下面的jQuery代码:

var x= $('#show').text();

var y= $('#show1').text();

Edited 已编辑

Or if you want to show value of textbox into label of dialog than please try below code :- 或者,如果您想在对话框标签中显示文本框的值,请尝试以下代码:-

var x= $("#textboxID").val()

And you can set this text to label:- 您可以将此文本设置为标签:-

$("#LabelID").val(x);

A little bit change in your code is needed, problem in your code is you are not assigning your 'x' to any field 需要对代码进行一些更改,代码中的问题是您没有将“ x”分配给任何字段

var x = document.getElementById("name").value;
document.getElementById("show").innerHTML = x;

Here is a jsFiddle, check out here. 这是一个jsFiddle,请在此处查看。

jsFiddle jsFiddle

Thanks 谢谢

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

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