1.驗證表單不為空
var?hasform =?{?"Name":?"名字",
????????????????"Id_card":?"身份證",?"PaySalary":?"月工資",
????????????????"CardCode":?"賬號",?"Fk_Subjectf_Code":?"功能科目",
????????????????"Birthday":?"出生日期",?"Start_Date":?"開始時間"
????????????};
????????????var?result?=?true;
????????????var?value;
????????????for?(var k in hasform?)?{
????????????????value?=?$("#"?+ k).val();
????????????????if?(value?==?"")?{
????????????????????alert(hasform?[k]?+?"不能為空!");
????????????????????result?=?false;
????????????????????break;
????????????????}
????????????}
?
2.獲取select下拉列表的值和文本
? 2.1 原生JS
? ? ?1:拿到select對象: var myselect=document.getElementById(“test”);
? ? ?2 拿到選中項的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所選中項的index
? ? ?3:拿到選中項options的value: myselect.options[index].value;
? ? ?4:拿到選中項options的text: myselect.options[index].text;
?2.2 jQuery
? ? ?1:var options=$(“#test option:selected”); //獲取選中的項
? ? ? 2:alert(options.val()); //拿到選中項的值
? ? ? 3:alert(options.text()); //拿到選中項的文本