我有以下jquery代码:
$(document).ready(function()
{
$("#build_table, a.coursename, .Start Date, .Book Title, .Book Author, .Book Isbn").click(function()
{
var whichButton = $(this).attr("class");
console.log("Whichbotton = " + whichButton);
var prog = $("#program option:selected").text();
var sch = $("#school option:selected").text();
var trm = $("#term option:selected").text();
var ext = $("#extension option:selected").text();
if(prog == "" || sch == "" || trm == "")
{
alert("Please enter a selection for each field");
}
else
{
$.get("build_table.php", {program: prog, school: sch, term: trm, extension: ext, button: whichButton},
function(table)
{ console.log("Entered table function");
$("#input_table").replaceWith("<div id='input_table'>" + table + "</div>");
});
}
});
});
在开始的路上,我有一个点击功能,我想为多个butttons工作。此代码将调用php文件来构建表,并且生成的表头具有不同的类名(例如coursename)。但它实际上并不适用于coursename,开始日期等,仅适用于build_table,它是首先构建表格的按钮。我错过了什么吗?我知道名字是正确的,我甚至试图从他们中的一个(a.coursename)中取出空间,但仍然没有用......
答案 0 :(得分:1)
我已经实施了这个及其工作。
HTML code:
<input type="button" value="Build table" id="build_table"/>
<input type="button" value="Course name" class="CourseName"/>
<input type="button" value="Start date" class="StartDate"/>
<input type="button" value="Book title" class="BookTitle"/>
<input type="button" value="Book author" class="BookAuthor"/>
<input type="button" value="Book isbn" class="BookIsbn"/>
jquery代码:
$(document).ready(function(){
$("#build_table, .CourseName, .StartDate, .BookTitle, .BookAuthor, .BookIsbn").click(function(){
alert("Yehh!! Its wroked :)");
//your further code
});
});