2017-03-13 16 views
-4

私はHTMLを持っていて、2 THを入れたい、もう1つは行のすべてのチェックボックスを選択することです。しかし、何もクリックしないと何も起こりません。Javascript in <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="alert('Hello! I am an alert box!!')"><b>Novel</b></th>