简体   繁体   English

如何在HTML中访问@ Html.TextBox值

[英]How to access @Html.TextBox value within the html

Is it possible to access @Html.TextBox value within the html 是否可以在html中访问@Html.TextBox

I have tried this approach 我已经尝试过这种方法

  @Html.TextBox("txtAmount")

  <script>
    var amount= document.getElementById("txtAmount").value;
    document.getElementById("my_amount").value = amount;
  </script>

Then reading the value within html 然后读取html中的值

    <p id="my_amount"></p>

So far this has not worked. 到目前为止,这没有用。 Any ideas? 有任何想法吗?

尝试这个

document.getElementById("my_amount").innerHTML = amount;
  @Html.TextBox("txtAmount")

  <script>
    var amount= document.getElementById("txtAmount").value;
    document.getElementById("my_amount").innerHTML= amount;
  </script>

you could also store values directly to JavaScript if needed 您还可以根据需要将值直接存储到JavaScript

  var amount= @model.YourValue ;

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

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