如何使用JAVASCRIPT将按钮添加到MVC中的HTML页面 [英] How to add button to an HTML page in MVC using JAVASCRIPT

查看:60
本文介绍了如何使用JAVASCRIPT将按钮添加到MVC中的HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JAVASCRIPT在MVC中向HTML页面添加按钮???请尽快帮助

How to add button to an HTML page in MVC using JAVASCRIPT???Please help soon

推荐答案

您好,



您可以使用以下函数使用Javascript函数创建动态输入类型。



Hello,

You can use below function for create dynamic input type using Javascript function.


document )。ready( function (){
(document).ready(function () {



add(button);

});




add("button");
});

function add(type) {
  //Create an input type dynamically.   
  var element = document.createElement("input");
  //Assign different attributes to the element. 
  element.type = type;
  element.value = type; // Really? You want the default value to be the type string?
  element.name = type; // And the name too?
  element.onclick = function() { // Note this is a function
    alert("Demo");
  };

  var foo = document.getElementById("SpanName");
  //Append the element in page (in span).  
  foo.appendChild(element);
}
document.getElementById("btnAdd").onclick = function() {
  add("text");
};
<input type="button" id="btnAdd" value="Add Text Field">
<p id="fooBar">Fields:</p>





如果您对此解决方案有任何疑问,请询问我。



If you have any query regarding this solution, please ask me.


这篇关于如何使用JAVASCRIPT将按钮添加到MVC中的HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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