2017-03-13 103 views
-4

我有一个HTML,我想把2 TH,第二个将是选择行的所有复选框。但是,当我点击没有发生。Javascript中<th>元素

<table id="books" class="m-0" width="100%" style="margin-top:0 !important;"> 
 
    <thead> 
 
     <tr> 
 
      <th><b>#</b></th> 
 
      <th><b>id</b></th> 
 
      <th><b>Name</b></th> 
 
      <th><b>Status</b></th> 
 
      <th><b>Images</b></th> 
 
      <th><b>Is Extension</b></th> 
 
      <th onclick=javascript:alert("Hello! I am an alert box!!") ><b>Novel</b></th> 
 
      <th><b>Novel</b></th> 
 
      <th><b>Actions</b></th> 
 
     </tr> 
 
     <tr> 
 
      <th><b>#</b></th> 
 
      <th><b>id</b></th> 
 
      <th><b>Name</b></th> 
 
      <th><b>Status</b></th> 
 
      <th><b>Images</b></th> 
 
      <th><b>Is Extension</b></th> 
 
      <th><b>ISBM</b></th> 
 
      <th><b>NOVEL</b></th> 
 
      <th><b>Actions</b></th> 
 
     </tr> 
 
    </thead> 
 
    <tbody>

+0

需要引用属性和你不需要使用JavaScript的':' – epascarello

+1

哦,看!控制台中出现错误。 – Turnip

回答

2

你有错误的语法,使用这样的

<th onclick="alert('Hello! I am an alert box!!')"><b>Novel</b></th> 
1

尝试

<th onclick="alert('Hello! I am an alert box!!');" ><b>Novel</b></th> 
1

如何使你的代码是由浏览器呈现:

<th onclick="javascript:alert(&quot;Hello!" i="" am="" an="" alert="" box!!")=""><b>Novel</b></th> 

为了解决这个问题,把它放在引号:

<th onclick="alert('Hello! I am an alert box!!')"><b>Novel</b></th>