单击按钮将Html表中的控件绑定

时间:2018-03-08 18:19:01

标签: html dom html-table

  • 我是一个非常新的编程,需要你的帮助和指导才能构建 我的自我。
  • 下面是编写的代码在按钮上的html表中添加控件 点击活动。
  • 但我发现它的执行没有运气。任何人都可以帮忙 知道什么是问题以及如何解决它

<!DOCTYPE html>
<html>
<body>

<p>Click the button to create a Text Field.</p>

<button onclick="myFunction()">Try it</button>
 <table id="tblCustomListData" border="1" width="100%" style="overflow-x:auto;">
              <thead>
                     <tr class="bgcolorgray">
                        <th>Sno</th>
                        <th >Current DR</th>
                     </tr>
                </thead>
            </table>
</div >
<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">


         
     
function myFunction() {

var txtHTML = "";
$('#tblCustomListData tbody').html('');

var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("id", "uniqueIdentifier");
x.setAttribute("value", "Hello!");
         document.body.appendChild(x);

 var row = document.createElement("tr");
 
                 txtHTML = txtHTML + "<tr>";
            	     txtHTML = txtHTML + "<td>";
                     txtHTML = txtHTML +  document.getElementById("uniqueIdentifier") + "</a>";
                     txtHTML = txtHTML + "</td>";
                 txtHTML = txtHTML + "</tr>";
                 
  $("#tblCustomListData").append(txtHTML);
  
  }
</script>

</body>
</html>

enter code here

1 个答案:

答案 0 :(得分:0)

您忘了添加document.getElementById("uniqueIdentifier").value

<!DOCTYPE html> <html> <body> <p>Click the button to create a Text Field.</p> <button onclick="myFunction()">Try it</button> <table id="tblCustomListData" border="1" width="100%" style="overflow-x:auto;"> <thead> <tr class="bgcolorgray"> <th>Sno</th> <th >Current DR</th> </tr> </thead> </table> </div > <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> function myFunction() { var txtHTML = ""; $('#tblCustomListData tbody').html(''); var x = document.createElement("INPUT"); x.setAttribute("type", "text"); x.setAttribute("id", "uniqueIdentifier"); x.setAttribute("value", "Hello!"); document.body.appendChild(x); var row = document.createElement("tr"); txtHTML = txtHTML + "<tr>"; txtHTML = txtHTML + "<td>"; txtHTML = txtHTML + document.getElementById("uniqueIdentifier").value + "</a>"; txtHTML = txtHTML + "</td>"; txtHTML = txtHTML + "</tr>"; $("#tblCustomListData").append(txtHTML); } </script> </body> </html>

p <- tibble(x, y) %>%
  table() %>% 
  CrossTable(prop.r = FALSE, prop.c = FALSE, prop.t = FALSE, prop.chisq = FALSE, fisher = TRUE) %>% 
  .$fisher.ts %>% 
  .$p.value

p
[1] 0.7761301