jQuery を使用するチュートリアルに基づいたコードに取り組んでいます$(document).ready
。これは、ページが読み込まれると (またはドキュメントの準備が整うと) すぐに作業を開始します。コードは非常に標準的で (私が jQuery についてほとんど知らないことから)、ページの読み込み時に機能します。
$(document).ready(function () {
// Do stuff here
});
しかし、コードが代わりに関数から実行されるように変更したいと思います。私の最初の考えは、関数をこれに変更するだけでよいということでした
$(function dothis() {
// Do stuff here
});
そして dothis(); で呼び出します。しかし、それを行うと、「dothis is not defined」エラーが発生します。私もいくつかの異なる方法を試しましたが、これを理解することができませんでした。これを希望どおりに機能させるには、何をする必要がありますか?
function searchCustomers() {
var searchvalue = document.getElementById('searchText2').value;
var searchtype = document.getElementById('searchType2').value;
//Just checking to make sure this part is working...
//alert(searchtype + ' ' + searchvalue)
// Run the "Do Stuff here"
var showDiv = document.getElementById('divCustomerGrid');
showDiv.style.display = 'block';
};