2016-04-28 10 views
0

データテーブルに配列する必要があるスクリプト内にデータがあります。私はこれを達成するための方法がわかりません。私は、データテーブルには、このデータをバインドし、それらにとして警告のポップアップを表示するのではなく、Webページに表示したいデータをASP.NETのデータテーブルにバインドする

<script> 
     var $textarea = $('#TextArea1'), $submit = $('#Submit1'); 
     $submit.click(function (e) { 
      e.preventDefault(); 
      sourceCode = $textarea.val(); 
      var $searchObject = $('<div id="Searching"></div>'); 
      $searchObject.append($(sourceCode)); 

      alert("Number of text boxes = " + $searchObject.find('[type=text]').length); 
      $searchObject.find('[type=text]').each(function() { 
       alert("Name of textbox = " + $(this).attr("name") + " and its ID is " + $(this).attr("id")); 

      }); 
      alert("Number of Submit Buttons = " + $searchObject.find('[type=submit]').length); 
      $searchObject.find('[type=submit]').each(function() { 
       alert("Name of Submit button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of Telephone entry fields = " + $searchObject.find('[type=tel]').length); 
      $searchObject.find('[type=tel]').each(function() { 
       alert("Name of Telephone entry field button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of Password boxes = " + $searchObject.find('[type=password]').length); 
      $searchObject.find('[type=password]').each(function() { 
       alert("Name of Password box = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of check boxes = " + $searchObject.find('[type=checkbox]').length); 
      $searchObject.find('[type=submit]').each(function() { 
       alert("Name of Submit button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of Radio buttons on page = " + $searchObject.find('[type=radio]').length); 
      $searchObject.find('[type=radio]').each(function() { 
       alert("Name of radio button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of drop down lists = " + $searchObject.find('select').length); 
      $searchObject.find('[type=select]').each(function() { 
       alert("Name of select button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of Images on page = " + $searchObject.find('img').length); 
      $searchObject.find('[type=img]').each(function() { 
       alert("Name of Image = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of Hyperlinks on page = " + $searchObject.find('a[href]').length); 

      alert("Number of Buttons  = " + $searchObject.find('[type=button]').length); 
      $searchObject.find('[type=button]').each(function() { 
       alert("Name of button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 

      }); 
      alert("Number of Date entry fields= " + $searchObject.find('[type=date]').length); 
      $searchObject.find('[type=date]').each(function() { 
       alert("Name of date button = " + $(this).attr("name") + " and its ID is =" + $(this).attr("id")); 
      });  
     }); 
    </script> 

:中

データがあります。データは、

<table> 
    <tr> 
     <th>Element </th> 
     <th>Element name</th> 
     <th>Element ID</th> 
    </tr> 
</table> 

のテーブルの下に配置する必要があります。これを行うにはどのような方法が最適でしょうか?誰もがこれを行うコードで私を助けてもらえますか?

ありがとうございます。

+0

あなたは何を求めているのでしょうか?スクリプトのデータからデータテーブルを作成したいのですか?もしそうなら、なぜコードをコードの中に記述してデータテーブルを作成しないのですか? –

答えて

0
<!DOCTYPE html> 
    <html> 
    <head> 
    <script src="https://code.jquery.com/jquery-1.9.1.js"></script> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width"> 
     <title>JS Bin</title> 
    </head> 
    <body> 
     <textarea id="TextArea1"></textarea> 
     <button id="Submit1">submit</button> 
    </body> 
    </html> 
<script> 
    $(document).ready(function(){ 
     var $textarea = $('#TextArea1'), $submit = $('#Submit1'); 
      $submit.click(function (e) { 
       e.preventDefault(); 
       sourceCode = $textarea.val(); 
       var $searchObject = $('<div id="Searching"></div>'); 
       $searchObject.append($(sourceCode)); 

       var table = $('<table border="1"></table>'); 
       table.append("<tr><td colspan='2'>Number of text boxes = " + $searchObject.find('[type=text]').length+"</td></tr>"); 

       $searchObject.find('[type=text]').each(function() { 
        table.append("<tr><td>Name of textbox = " + $(this).attr("name") + "</td><td> and its ID is " + $(this).attr("id")+"</td></tr>"); 
       }); 

       table.append("<tr><td colspan='3'>Number of Submit Buttons = " + $searchObject.find('[type=submit]').length+"</td></tr>"); 
       $searchObject.find('[type=submit]').each(function() { 
        table.append("<tr><td>Name of Submit button = " + $(this).attr("name") + "</td><td> and its ID is =" + $(this).attr("id")+"</td></tr>"); 
       }); 

       //Added remaining code here 

       table.appendTo($(this).parent());   
      }); 
    }); 
</script> 

テーブルにデータを追加するスクリプトが見つかりました。 Tnxからhttp://forums.asp.net/members/raju%20dasa.aspx

関連する問題