如何在HTML中引用标记值

如何在HTML中引用标记值,html,forms,select,input,Html,Forms,Select,Input,我有以下代码: <select name ="selected"> <option> Option1 </option> <option> Option2 </option> </select> <input name = "text" type = "text" value = "The value of the selected value of the drop d

我有以下代码:

<select name ="selected">
   <option>
      Option1
   </option>
   <option>
      Option2
   </option>
</select>
<input name = "text" type = "text" value = "The value of the selected value of the drop down list"/>

选择1
选择2
如何在文本的值中引用选中的的值?

您可以使用jQuery


alert(值为“+$”('select[name=“selected”]”).val());

要给出一个稍微扩展的答案,结合一些评论中已经说过的内容,有几件事你应该知道:

  • HTML是“静态”文档标记-它不从其他元素中提取值,等等。它只是标记现有内容
  • 如果您想要实现您所描述的行为,您必须使用web浏览器支持的脚本语言……特别是,您将使用Javascript。(“jQuery”在另一个答案中提到,是一个框架,旨在简化网页的Javascript编程。一旦您理解了这里的概念,就值得研究)

  • 我建议你去看看网络基础课程,这可能会对你有很大帮助。

    你需要使用JavaScript,因为HTML是一种静态语言。如果你需要,请使用JavaScript。Ohkay thankx我会研究它!