点击按钮后插入HTML ID内的文本(无javascript) [英] Insert text inside html id after clicking a button (without javascript)

查看:95
本文介绍了点击按钮后插入HTML ID内的文本(无javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括后pressing一个按钮一个文本框(ID =按钮3)里面的一些文字。

I want to include some text inside a textbox (ID=button3) after pressing a button.

我有以下的html:

<div id="collapse2" style="display:none">
   <span id="button3">text before pressing the button></span>
</div>

和JavaScript的里面我知道我可以在两种不同的方式解决我的问题。

And inside javascript I know I can solve my problem in two different ways.

选项1:

var element=document.getElementById("button3");
element.innerHTML="text after pressing the button";

选项2:

$('#button3').text('text after pressing the button');

你能不能给我一份有剃刀/ HTML辅助第三位的选择吗?这是与另外一个问题我昨天发布(<一相关href=\"http://stackoverflow.com/questions/21913070/cant-write-razor-variable-inside-html-id-class-element-dinamically\">My另一个问题)。不过,我想这一次我能够解释以更好的方式我的问题。

Can you give me a 3rd option with razor/html helpers? This is related with another question I posted yesterday (My other question). However, I think this time I was able to explain my problem in a better way.

推荐答案

要做到这一点完全在剃须刀,你将被要求向服务器发出呼叫。要做到这一点,让你的观点强类型和使用剃刀从模型中取按钮3的值。

To do this entirely within razor, you will be required to make a call to the server. To do this, make your view strongly typed and take the button3 value from the model using razor.

输入参数(字符串button3Value =初始值)添加到您的控制器的方法。默认给你的初始值按钮3。

Add an input parameter (string button3Value="initial value") to your Controller Method. Default this to your initial button3 value.

您可以再使用一个@ Html.ActionLink并从buttonclick通过新的按钮3的值。这将刷新页面适当的值。

You can then use an @Html.ActionLink and pass the new button3 value from your buttonclick. This will reload the page with the appropriate value.

这篇关于点击按钮后插入HTML ID内的文本(无javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆