我有一个用于 Ajax 调用的 php 页面。<ul>
它以 a和<li>
items的形式产生输出。这些项目被用作原始页面上输入字段的自动完成。我遇到的问题是找到一种优雅的方法来更新其他字段,其中一些是隐藏的,在用户克隆它们之后,基于此 Ajax 调用和后续 sql 查询的结果。更喜欢使用 jQuery,我相信这是可能的。我只是找不到简单的解决方案。查看我目前正在使用的所有 next().next().next()。丑陋的!
首先是php页面:
<?PHP
include "dbconnect.php";
$partialSection=$_POST['partialSection'];
$school_id=$_POST['school_id'];
$sql="select course_section_code,course_name,course_credit_hours,school_id,ext_course_id from ext_courses
where course_section_code like '%$partialSection%' and school_id = $school_id";
$result = db_query($sql);
if (mysql_num_rows($result)==0){
echo "<DIV>No external courses match your query for $partialSection at $school_id. Would you like to enter a new course? <button onclick='new_section()'>Yes</button></DIV>";
}
$output="<ul>";
while ($record = get_record($result))
{
$section=$record['course_section_code'];
$course_title=$record['course_name'];
$credits=$record['course_credit_hours'];
$school_id=$record['school_id'];
$ext_course_id=$record['ext_course_id'];
$output.="<li class=resultcss onmouseover='this.style.color=\"63b8ee\";this.style.backgroundColor=\"FFFFFF\"' onmouseout='this.style.color=\"FFFFFF\";this.style.backgroundColor=\"63b8ee\"' onclick='$(\".popup\").hide();$(\"*:focus\").val(\"".$section."\");$(\"*:focus\").next().next().next().val(\"".$course_title."\");$(\"*:focus\").next().next().next().next().next().val(\"".$credits."\");enter_data.ext_course_id0.value=\"".$ext_course_id."\"'>".$section."</li>";
}
$output.="</ul>";
echo $output;
?>
好的,现在这是表单的 HTML:
<div class="cloneMe">
<div>
<label for="course_section0" class="">Section: <span class="requiredField">*</span></label>
<input type="text" class="cinputs needsPopup" name="course_section[]" id="course_section0" size="8" onfocus="check_contents();" ONKEYUP="get_section(this.value,$('#school_id').val());" autocomplete="off">
<input type="hidden" class="" name="ext_course_id[]" id="ext_course_id0">
<label for="course_name0" class="">Name: <span class="requiredField">*</span></label>
<input type="text" class="cinputs" name="course_name[]" id="course_name0" size="30">
<label for="course_credits0" class="">Credits: <span class="requiredField">*</span></label>
<input type="text" class="cinputs" name="course_credits[]" id="course_credits0" size="3">
<label for="course_grade0" class="">Grade: <span class="requiredField">*</span></label>
<select class="cinputs" name="course_grade[]" id="course_grade0">
<option>Grade:</option>
<option>A</option>
<option>A-</option>
<option>B+</option>
<option>B</option>
<option>B-</option>
<option>C+</option>
<option>C</option>
<option>C-</option>
<option>D+</option>
<option>D</option>
<option>D-</option>
<option>F</option>
<option>P</option>
<option>CR</option>
<option>NC</option>
<option>IP</option>
<option>I</option>
</select>
<label for="hours_awarded0" class="">Hours Awarded: <span class="requiredField">*</span></label>
<input type="text" class="cinputs" name="hours_awarded[]" id="hours_awarded0" size="3">
<label for="baker_equiv0" class="">Baker Equivalent: <span class="requiredField">*</span></label>
<input type="text" class="cinputs needsPopup" name="baker_equiv[]" id="baker_equiv0" size="8" ONKEYUP="get_equiv(this.value);"> <input type="hidden" class="" name="baker_equiv_id[]" id="baker_equiv_id0">
<label for="quest0" class="">Quest: <span class="requiredField">*</span></label>
<input type="text" class="cinputs" name="quest[]" id="quest0" size="3">
<button type="button" class="clone">Add Course</button>
<button type="button" class="remove">Remove</button>
</div>
链接在红色括号中显示克隆的表格。
http://www.rp-software.com/Screenshot.JPG
感谢您的任何建议!