删除我的js按钮中的插入栏

时间:2017-05-31 18:58:04

标签: javascript html

这是我的按钮,他工作得很好,但他很丑......:



function MyFunc() {
  var MyDiv = document.createElement("div");
  document.getElementById("MyBody").appendChild(MyDiv);
  var MyButton = document.createElement("input");
  MyButton.id = "Mybuttonid";
  MyButton.className = "Mybuttonclass";
  MyButton.setAttribute("value", "open");
  MyDiv.appendChild(MyButton);
}

#Mybuttonid {
  padding: 2pt;
  display: block;
  width: 100%;
  text-align: center;
  border-style: none;
  border-bottom-left-radius: 10pt;
  border-bottom-right-radius: 10pt;
  background-color: rgba(59, 59, 59, 1);
  color: rgba(255, 255, 255, 1);
  font-family: Arial, sans-serif;
  font-size: 15pt;
  cursor: pointer;
  outline-style: none;
}

<html>

<head>
</head>

<body id="MyBody">
  <script>
    MyFunc();
  </script>
</body>

</html>
&#13;
&#13;
&#13;

我想删除单击按钮时停留的插入栏

我会尝试放置图片.... The Image...

1 个答案:

答案 0 :(得分:0)

您还需要添加属性type="button"

function MyFunc() {
  var MyDiv = document.createElement("div");
  document.getElementById("MyBody").appendChild(MyDiv);
  var MyButton = document.createElement("input");
  MyButton.id = "Mybuttonid";
  MyButton.className = "Mybuttonclass";
  MyButton.setAttribute("value", "open");
  MyButton.setAttribute("type", "button");// added line
  MyDiv.appendChild(MyButton);
}

MyFunc();
#Mybuttonid {
  padding: 2pt;
  display: block;
  width: 100%;
  text-align: center;
  border-style: none;
  border-bottom-left-radius: 10pt;
  border-bottom-right-radius: 10pt;
  background-color: rgba(59, 59, 59, 1);
  color: rgba(255, 255, 255, 1);
  font-family: Arial, sans-serif;
  font-size: 15pt;
  cursor: pointer;
  outline-style: none;
}
<body id="MyBody">
</body>